标签:
遍历 <ul> 列表: 2016-5-20
<script type="text/javascript" src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script> <script type="text/javascript"> $(function(){ $("#button").click(function(){ //遍历 $("ul li").each(function(){ console.log($(this).text()) }); $("ul li").each(function(i,element){ console.log($(this).text()) console.log($(element).text()); console.log(i); }); }); }); </script> <ul> <li>111</li> <li>222</li> <li>333</li> <li>444</li> </ul> <input type="button" id="button" value="遍历">
遍历obj对象: 2016-5-20
var obj={ a:1, b:2, c:3 } for(var item in obj){ console.log(item); }
遍历表单文本框:
<script type="text/javascript" src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script> <script type="text/javascript"> $(function(){ $("#button").click(function(){ //遍历表单文本框 $("#form1 input[name]").each(function(){ $(this).bind("blur",function(){ testtest($(this)); });//注意blur事件写法! function testtest(_this) { console.log(_this.val()); } }) }); }); </script> <form method="post" action="" id="form1"> <input type="text" name="a1" value="a111"><br> <input type="text" name="a2" value="a222"><br> <input type="text" name="a3" value="a333"><br> <input type="text" name="a4" value="a444"><br> <input type="button" value="button" id="button"> </form>
...
标签:
原文地址:http://www.cnblogs.com/qq21270/p/5512976.html