2020-07-09 15:17发布
页面中引用了jquery,第一想到的就是序列化,下面写一个jquery的扩展方法
$.fn.serializeObject = function()
{
var obj = {};
var arr = this.serializeArray();
$.each(arr , function() {
if (obj[this.name]) {
if (!obj[this.name].push) {
obj[this.name] = [obj[this.name]];
}
obj[this.name].push(this.value || '');
} else {
obj[this.name] = this.value || '';
});
return obj;
};
这个方法是将表单序列化成json的。
最多设置5个标签!
页面中引用了jquery,第一想到的就是序列化,下面写一个jquery的扩展方法
$.fn.serializeObject = function()
{
var obj = {};
var arr = this.serializeArray();
$.each(arr , function() {
if (obj[this.name]) {
if (!obj[this.name].push) {
obj[this.name] = [obj[this.name]];
}
obj[this.name].push(this.value || '');
} else {
obj[this.name] = this.value || '';
}
});
return obj;
};
这个方法是将表单序列化成json的。
一周热门 更多>