对象遍历
例子
例子
例如对象遍历实现全选
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>对象遍历全选和全不选</title> <script src="../js/jquery-1.8.3.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> $(function(){ $("#quanxuan").click(function(){ // 变量使用与JS一样 var sta = this.checked; // 对象遍历方式遍历所有满足条件的元素 $("body table #ren").each(function(){ this.checked=sta; }); }); }); </script> </head> <body> <font id="p11" color="#000000">WWW</font> <table border="1px" width="400px" align="center"> <tr> <th>全选:<input type="checkbox" name="quanxuan" id="quanxuan" value="" onclick="change()"/></th> <th>编号</th> <th>姓名</th> <th>年龄</th> </tr> <tr> <td><input type="checkbox" name="ren" id="ren" value="" /></td> <td>1</td> <td>qqq</td> <td>25</td> </tr> <tr> <td><input type="checkbox" name="ren" id="ren" value="" /></td> <td>1</td> <td>qqq</td> <td>25</td> </tr> <tr> <td><input type="checkbox" name="ren" id="ren" value="" /></td> <td>1</td> <td>qqq</td> <td>25</td> </tr> <tr> <td><input type="checkbox" name="ren" id="ren" value="" /></td> <td>1</td> <td>qqq</td> <td>25</td> </tr> </table> </body> </html>
2.数组遍历
例子:
时间: 2024-10-06 03:13:49