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();