标签:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div> <input type="button" value = "全选" ondblclick="CheckAll()"> <input type="button" value="取消" ondbclick="CancleAll()"> <input type="button" value="反选" ondblclick="ReverseAll()"> </div> <table> <theard> <tr> <th>序号</th> <th>用户名</th> <th>年龄</th> </tr> </theard> <tbody id="tb"> <tr> <td><input class="c1" type="checkbox"></td> <td>Wyc</td> <td>17</td> </tr> <tr> <td><input class="c1" type="checkbox"></td> <td>Wyc</td> <td>18</td> </tr> <tr> <td><input class="c1" type="checkbox"></td> <td>Wyc</td> <td>19</td> </tr> </tbody> </table> <script> function CeckAll(){ var tb = document.getElementById("td"); var checks = tb.getElementsByClassName("c1"); for(var i=0;i<checks.length;i++){ var current_check = checks[i]; current_check.checked =true; } } function CancleAll(){ var tb = document.getElementById("tb"); var checks = tb.getElementsByClassName("c1"); for(var i=0;i<checks.length;i++){ var current_check = checks[i]; current_check.checked = false; } } function ReverseAll(){ var tb = document.getElementById("tb"); var checks = tb.getElementsByClassName("c1"); for(var i=0;i<checks.length;i++){ var current_check = checks[i]; if(current_check.checked){ current_check.check = false; }else{ current_check.checked = true; } } } </script> </body> </html>
标签:
原文地址:http://www.cnblogs.com/wuyongcong/p/5659008.html