serialize将表单序列化成字符串
serializeArray将表单序列化成数组
serializeObject序列化为JSON对象
注:当表单中参数出现同名时,serializeObject会取第一个,而忽略后续的
$.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;
};
$.fn.extend({
serializeObject:function(){
var p={},d={},a=this.serializeArray();
$.each(a,function(){
var s=p[this.name];
s=!s?[]:s;
s.push(this.value);
p[this.name]=s;
});
for(var k in p){
d[k]=p[k].join()
}
return d;
}
});
jQuery.extend() 合并对象
JSON.parse()将字符串解析成Json对象
JSON.stringify()将Json对象解析成字符串