Jquery将Form表单序列化为JSON对象 Serialize Form to JSON

Jquery将Form表单序列化为JSON对象 

$("form").serializeObject(); 

类似

$("form").serialize(); 
$("form").serializeArray();  
$.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;
};

来源:https://css-tricks.com/snippets/jquery/serialize-form-to-json/

其他方法:

http://blog.csdn.net/flashdelover/article/details/8185775

http://marsvaadin.iteye.com/blog/1717188

发表评论

邮箱地址不会被公开。 必填项已用*标注