form表单的数据 转json
form表单的数据 转json
将form表单中的数据序列化数组后转换为Json
一个jquery的扩展方法(网上摘的):
$.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;
};
调用
var para = $('form').serializeObject() ;
para = JSON.stringify(para) ; //para是json字符串

浙公网安备 33010602011771号