【jQuery - serializeArray 序列化表单值并转为键值对】

原文找不到了,先挂原创。原作者看到,请联系我,我改为转载。

/**
 * 序列化表单值并转为键值对
 */
function getFormJson(form) {  
    var o = {};  
    var a = $(form).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;  
}  

版权声明:本文为qq_35453862原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。