复选框中有全选的情况~~
JSP页面中一堆复选框,第一个是全选,如果勾选了“全选”则剩下的全部自动勾选,这个要怎么写??
[解决办法]
<html><head><script>function checkAll(obj){ var checkboxs = document.getElementsByName("checkA"); if(checkboxs) { for(var i = 0; i < checkboxs.length; i++) { var cb = checkboxs[i]; cb.checked = obj.checked; } }}</script></head><body><h1>全选/全不选</h1><table border="1"> <tr> <td><input type="checkbox" name="checkAll" onclick="checkAll(this);"></td> <td width="120px"></td> </tr> <tr> <td><input type="checkbox" name="checkA"></td> <td>选择1</td> </tr> <tr> <td><input type="checkbox" name="checkA"></td> <td>选择2</td> </tr> <tr> <td><input type="checkbox" name="checkA"></td> <td>选择3</td> </tr> <tr> <td><input type="checkbox" name="checkA"></td> <td>选择4</td> </tr></table></body></html>