form 表单获取所有数据 封装方法

function getFormJson(frm) {
var o = {};
var a = $(frm).serializeArray();
$.each(a, function () {
if (o[this.name] !== undefined) {
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 obj = getFormJson($('#form'));//json数据

posted @ 2017-10-11 16:46  xzzzys  Views(1053)  Comments(0Edit  收藏  举报