赞
踩
1.获取input值 的6种方法:
- <!doctype html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>测试页面</title>
- <script type="text/javascript" src="jquery.js"></script>
- </head>
- <body>
- <div id="gjdiv" class="gjc">
- <input type="hidden" id="title" name="gj" value="113"/>
- <input type="hidden" id="brief" name="gj" value="df"/>
- <input type="hidden" id="content" name="gj" value="sg"/>
- </div>
-
- <script>
- $(document).ready(function(){
- var param0 = $("input[name='gj']").val();
- console.log("param0:"+param0);
-
- var param1 = $(".gjc input[name='gj']").val();
- console.log("param1:"+param1);
-
- var param2 = $("#gjdiv input[name='gj']").val();
- console.log("param2:"+param2);
-
- var param3 = $("div input[name='gj']").val();
- console.log("param3:"+param3);
-
- var param4 = $("#gjdiv>input[name='gj']").val();
- console.log("param4:"+param4);
-
- var param5 = $("#gjdiv :input[name='gj']").val();
- console.log("param5:"+param5);
-
- console.log("stringify():"+JSON.stringify(param0));
- //console.log(JSON.parse(param));
-
- })
-
- </script>
- </body>
- </html>
结果:
获取的都是第一个input的值。
2.将input值序列化:
- <!doctype html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>测试页面</title>
- <script type="text/javascript" src="jquery.js"></script>
- </head>
- <body>
- <div id="gjdiv" class="gjc">
- <input type="hidden" id="title" name="gj" value="113"/>
- <input type="hidden" id="brief" name="gj" value="df"/>
- <input type="hidden" id="content" name="gj" value="sg"/>
- </div>
-
- <script>
- $(document).ready(function(){
- var param0 = $("input[name='gj']").serialize();
- console.log("param0:"+param0);
-
- var param1 = $(".gjc input[name='gj']").serialize();
- console.log("param1:"+param1);
-
- var param2 = $("#gjdiv input[name='gj']").serialize();
- console.log("param2:"+param2);
-
- var param3 = $("div input[name='gj']").serialize();
- console.log("param3:"+param3);
-
- var param4 = $("#gjdiv>input[name='gj']").serialize();
- console.log("param4:"+param4);
-
- var param5 = $("#gjdiv :input[name='gj']").serialize();
- console.log("param5:"+param5);
-
- console.log("stringify():"+JSON.stringify(param0));
- //console.log(JSON.parse(param));
-
- })
-
- </script>
- </body>
- </html>
结果:
参考:
http://blog.csdn.net/dazhi_100/article/details/29582883
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。