jquery 实现表单数据转化为对象格式

 1 $.fn.serializeObject = function()    
 2 {    
 3    var o = {};    
 4    var a = this.serializeArray();    
 5    $.each(a, function() {    
 6        if (o[this.name]) {    
 7            if (!o[this.name].push) {    
 8                o[this.name] = [o[this.name]];    
 9            }    
10            o[this.name].push(this.value || '');    
11        } else {    
12            o[this.name] = this.value || '';    
13        }    
14    });    
15    return o;    
16 }; 

调用方式:

获取form表单元素

1 let obj = $('#listform').serializeObject();
原文地址:https://www.cnblogs.com/summer0319/p/7227968.html