form 转json
2015-08-07 10:25
686 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="application/javascript" src="js/jquery-2.0.3.js"></script> <title>无标题文档</title> <script type="application/javascript"> $.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; }; function onClik(){ //var data = $("#form1").serializeArray(); //自动将form表单封装成json //alert(JSON.stringify(data)); var jsonuserinfo = $('#form1').serializeObject(); alert(JSON.stringify(jsonuserinfo)); } </script> </head> <body> <form id="form1" name="form1" method="post" action=""> <p>进货人 : <label for="name"></label> <input type="text" name="name" id="name" /> </p> <p>性别: <label for="sex"></label> <select name="sex" size="1" id="sex"> <option value="1">男</option> <option value="2">女</option> </select> </p> <table width="708" border="1"> <tr> <td width="185">商品名</td> <td width="205">商品数量</td> <td width="296">商品价格</td> </tr> <tr> <td><label for="pro_name"></label> <input type="text" name="pro_name" id="pro_name" /></td> <td><label for="pro_num"></label> <input type="text" name="pro_num" id="pro_num" /></td> <td><label for="pro_price"></label> <input type="text" name="pro_price" id="pro_price" /></td> </tr> <tr> <td><input type="text" name="pro_name2" id="pro_name2" /></td> <td><input type="text" name="pro_num2" id="pro_num2" /></td> <td><input type="text" name="pro_price2" id="pro_price2" /></td> </tr> </table> <p> </p> <input type="button" name="submit" onclick="onClik();" value="提交"/> </form> </body> </html> [html] view plaincopy在CODE上查看代码片派生到我的代码片 <span style="font-size:32px;"><strong>代码效果演示:</strong></span>
原文地址:http://blog.csdn.net/zhangdaiscott/article/details/18456215
相关文章推荐
- JS学习第五天----类型,值,和变量
- [js开源组件开发]loading加载效果
- JavaScript之document.cookie使用总结
- 《JavaScript函数式编程》读后感
- JavaScript调试技巧之console.log()详解--2015-08-07
- js 关于在子类构造函数中加入call(this)的用意!
- JavaScript中setInterval函数应用常见问题之一(第一个参数不加引号与加引号的区别)
- JS控制HTML元素的显示和隐藏
- 跳过登陆页面直接访问该jsp文件了,这样不好,请问大家如何避免这种问题?
- FastJson:省略小数点后0的Bug的跟踪
- jsp中,对window对象的简单总结
- JavaScript基础
- JavaScript:改变HTML图像
- JavaScript:验证输入
- JavaScript数组和对象
- JavaScript Switch语句
- JavaScript For/In语句
- JavaScript 表单验证
- Js-最严谨的校验邮箱地址的正则表达式
- JavaScript HTML DOM事件