<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>
原文地址:https://www.cnblogs.com/xy-ouyang/p/10854383.html
时间: 2024-10-09 02:00:06