依赖于jquery将表单元素序列化为json格式,实现代码如下:
//定义serializeObject方法,序列化表单
$.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] ];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
使用:
var params = $('form').serializeObject();
序列化后的结果:
{
"receiverIds": "WUHUI",
"receiverNames": "吴辉",
"msgTitle": "回复:是的",
"typeTag": "02",
"msgContents": "<p>阿斯蒂芬</p>",
"parentId": "6d959fc6f5ce4d2b86ccde71bee570ac"
}
参考:
最新评论
本来在正常下载,突然就不能下载,并出现报错:a socket operation was attempted to an unreachable network。请问是什么原因呢
试了,还是不行,能不能更新一下
试了,确实不行,能不能更新一下
也推荐一下我自己写的 https://twitdown.com