复制代码 代码如下:
(function($){ 
$.fn.serializeObject=function(){ 
           var inputs=$(this).find("input,textarea,select"); 
           var o = {}; 
           $.each(inputs,function(i,n){ 
               switch(n.nodeName.toUpperCase()){ 
                   case "INPUT": 
                       if($(n).is(":checkbox")){ 
                           if($(n).is(":checked")){ 
                               o[n.name]=true; 
                           }else{ 
                               o[n.name]=false; 
                           } 
                       }else if($(n).is(":radio")){ 
                           if($(n).is(":checked")){ 
                               o[n.name]=n.value; 
                           } 
                       }else{ 
                           o[n.name]=n.value;  
                       } 

                       break; 
                   case "TEXTAREA": 
                       o[n.name]=$(n).text(); 
                       break; 
                   case "SELECT": 
                       o[n.name]=n.value; 
                       break; 
               } 
           }); 
           return o; 
       } 
})(jQuery);
标签:
json,jQuery

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com

评论“jQuery把表单元素变为json对象”

暂无“jQuery把表单元素变为json对象”评论...