jquery把form转化成json对象

来源:互联网 发布:淘宝女性催情药 编辑:程序博客网 时间:2024/06/07 19:23
function formToJson(formObj){    var o = {};    var a = formObj.serializeArray();    $.each(a, function() {        if(this.value){            if (o[this.name]) {                if (!o[this.name].push) {                    o[this.name] = [ o[this.name] ];                }                    o[this.name].push(this.value || null);            } else {                if($("[name='"+this.name+"']:checkbox",formObj).length){                    o[this.name]=[this.value];                }else{                     o[this.name] = this.value || null;                }            }        }    });    return o;};
 
var jsonuserinfo = $.toJSON($('#form').serializeObject());  
0 0
原创粉丝点击