Jquery 将表单序列化为Json对象

实现封装写在jquery.js里面的新增对象

/*
 * 表单序列化为json对象
 */
    (function($){  
            $.fn.serializeJson=function(){  
                var serializeObj={};  
                var array=this.serializeArray();  
                var str=this.serialize();  
                $(array).each(function(){  
                    if(serializeObj[this.name]){  
                        if($.isArray(serializeObj[this.name])){  
                            serializeObj[this.name].push(this.value);  
                        }else{  
                            serializeObj[this.name]=[serializeObj[this.name],this.value];  
                        }  
                    }else{  
                        serializeObj[this.name]=this.value;   
                    }  
                });  
                return serializeObj;  
            };  
        })(jQuery);  

posted @ 2017-08-10 17:10  前端小脚丫  阅读(157)  评论(0编辑  收藏  举报