本文介绍了jquery form表单序列化为对象的实现代码,有需要的朋友参考下。
例子,jquery form表单序列化为对象。
代码:
$.fn.serializeObject = function() { 
var o = {}; 
var a = this.serializeArray(); 
$.each(a, function() { 
if (o[this.name]) { 
if (!o[this.name].push) { 
o[this.name] = [ o[this.name] ]; 
} 
o[this.name].push(this.value || ''); 
} else { 
o[this.name] = this.value || ''; 
} 
}); 
return o; 
}