本文共 742 字,大约阅读时间需要 2 分钟。
Javascript实现表格的全选框: http://www.cnblogs.com/sanshi/archive/2009/02/17/javascript_table_select_all_checkbox.html <table border="1" cellpadding="3" cellspacing="0"> <tr> <th> <input type="checkbox" οnclick="checkAll(this, 'item1');" /> </th> <th>ID</th> <th>用户名</th> </tr> <tr> <td> <input type="checkbox" class="item1" /> </td> <td>1001</td> <td>张三</td> </tr> <tr> <td> <input type="checkbox" class="item1" /> </td> <td>1002</td> <td>李四</td> </tr> </table> function checkAll(sender, checkClass) { var checkItems = document.getElementsByTagName('input'); for (var i = 0; i < checkItems.length; i++) { var checkItem = checkItems[i]; if (checkItem.type === 'checkbox' && checkItem.className === 'item1') { checkItem.checked = sender.checked; } } }