1.写一个全局方法
$.fn.serializeObject = function () {
var o = {}
var a = this.serializeArray();
$.each(a, function () {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
if (this.value != null) {
o[this.name].push($.trim(this.value));
} else {
o[this.name].push("");
}
} else {
if (this.value != null) {
o[this.name] = $.trim(this.value);
} else {
o[this.name] = "";
}
}
});
return o;
};
2.使用方法
let obj = $('选中form').serializeObject();