- 序列化为字符串
var params1 = $(#myform).serialize();//name=zhangsan&sex=1&age=20
- 序列化为数组
$(#myform).serializeArray();//[Object, Object, Object]
- 序列化为对象
//form表单上数据转成[{name:value},,,,] $.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; };
js将form内的表单序列化为json字符串、数组、对象
最新推荐文章于 2023-11-23 18:21:58 发布