jquery.serializejson.js:下载地址 :https://pan.baidu.com/s/1mz3kHIdcW_pFkAzQxYE1YQ
提取码:oyyq ,下载引用query.serializejson.js即可;
下面是自己封装的获取from参数并转换为json对象:
<body> <form id='zhi'> <input name="xxx" value="000" /> <input name="check[]" type="checkbox" value="1" /> <input name="check[]" type="checkbox" value="2" /> <input name="check[]" type="checkbox" value="3" /> <button onclick="return dianji();"></button> </form> </body>
<script src="https://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> (function($) { $.fn.extend({ serializeJSONOBJ:function() { var obj_xsw={}; var array=this.serializeArray(); $(array).each(function(){ if(this.name.indexOf('[]')!=-1){ var name_sp=this.name.split('[]'); var name=name_sp[0]+name_sp[1]; if(obj_xsw[name]){ obj_xsw[name].push(this.value); }else{ obj_xsw[name]=[this.value]; } }else{ obj_xsw[this.name]=this.value; } }); return obj_xsw; } }); }(jQuery)); function dianji(){ console.log($('#zhi').serializeJSONOBJ()); return false; } </script>