- html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Titletitle>
- head>
- <body>
- <table border="1">
- <thead>
- <tr>
- <input type="button" value="全选" onclick="ChooseAll();"/>
- <input type="button" value="取消" onclick="CancelAll();"/>
- <input type="button" value="反选" onclick="ReverseAll();"/>
- tr>
- thead>
-
- <tbody id="tb">
- <tr>
- <td>
- <input type="checkbox" id="test"/>
- td>
- <td>test1td>
- <td>test1td>
- tr>
- <tr>
- <td>
- <input type="checkbox" />
- td>
- <td>test2td>
- <td>test2td>
- tr>
- <tr>
- <td>
- <input type="checkbox" />
- td>
- <td>test2td>
- <td>test2td>
- tr>
- tbody>
-
- table>
-
- <script>
- function ChooseAll() {
- var tb = document.getElementById('tb');
- //获取tb下所有的tr
- var tr_list = tb.children;
- for(var i=0;i
length;i++){ - //循环所有的tr,获取当前的tr
- var current_tr = tr_list[i];
- var checkbox = current_tr.children[0].children[0];
- //勾选
- checkbox.checked = true;
- }
- }
-
- function CancelAll() {
- var tb = document.getElementById('tb');
- var tr_list = tb.children;
- for(var i=0;i
length;i++){ - var current_tr = tr_list[i];
- var checkbox = current_tr.children[0].children[0];
- checkbox.checked = false;
- }
- }
-
- function ReverseAll() {
- var tb = document.getElementById('tb');
- var tr_list = tb.children;
- for(var i=0;i
length;i++){ - var current_tr = tr_list[i];
- var checkbox = current_tr.children[0].children[0];
- if(checkbox.checked){
- checkbox.checked = false;
- }else {
- checkbox.checked = true;
- }
- }
- }
- script>
- body>
- html>