jquery将表单序列化json对象
2020-12-13 16:22
标签:style class blog code http tar 实例下载 jquery将表单序列化json对象,搜素材,soscw.com jquery将表单序列化json对象 标签:style class blog code http tar 原文地址:http://www.cnblogs.com/yeminglong/p/3799282.html $.fn.serializeObject = function () {
var obj = {};
var count = 0;
$.each(this.serializeArray(), function (i, o) {
var n = o.name, v = o.value;
count++;
obj[n] = obj[n] === undefined ? v
: $.isArray(obj[n]) ? obj[n].concat(v)
: [obj[n], v];
});
//obj.nameCounts = count + "";//表单name个数
return JSON.stringify(obj);
};
调用示例:var serStr = $(‘#form1‘).serializeObject();