码迷,mamicode.com
首页 > Web开发 > 详细

把表单转成json,并且name为key,value为值

时间:2017-06-19 14:28:25      阅读:320      评论:0      收藏:0      [点我收藏+]

标签:jquer   else   class   form   query   data-   com   net   his   

http://jsfiddle.net/sxGtM/3/
http://stackoverflow.com/questions/1184624/convert-form-data-to-js-object-with-jquery

/*把表单转成json,并且name为key,value为值*/
 $.fn.serializeObject = function()
 {
     var o = {};
     var a = this.serializeArray();
     $.each(a, function() {
         if (o[this.name] !== undefined){
             if (!o[this.name].push) {
                 o[this.name] = [o[this.name]];
             }
             o[this.name].push(this.value || ‘‘);
         } else {
             o[this.name] = this.value || ‘‘;
         }
     });
     

  

把表单转成json,并且name为key,value为值

标签:jquer   else   class   form   query   data-   com   net   his   

原文地址:http://www.cnblogs.com/pangguoming/p/7048275.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!