jquery扩展方法(表单数据格式化为json对象)
jquery扩展方法(表单数据格式化为json对象)
<script type="text/javascript"> // 将表单数据序列化为一个json对象,例如 {"name":"zs", "age":10} // 使用:var jsonObj = $("#formId").serializeObject(); $.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; }; </script>
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
更多精彩