[英]Check all check box with a check box click
<script> function chkall() { var checkbox = document.getElementById('checkbox'); var checkbox2 = document.getElementById('checkbox2'); if(checkbox.checked==true) { checkbox2.checked=true; } } </script>
<table width="10%" border="0"> <tr> <th scope="col"><input type="checkbox" onclick="chkall()" name="checkbox" id="checkbox" /></th> </tr> <?php $i=0; while($i<5) { ?> <tr> <th scope="col"><input type="checkbox" name="checkbox2" id="checkbox2" /></th> </tr> <?php $i++; } ?> </table>
我在while循环中运行了5次的复选框。 我在循环上方有一个复选框。 单击上面的复选框时,我想选中循环内的所有复选框。
function checkAll(ele) {
var checkboxes = document.getElementsByTagName('input');
if (ele.checked) {
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].type == 'checkbox') {
checkboxes[i].checked = true;
}
}
} else {
for (var i = 0; i < checkboxes.length; i++) {
console.log(i)
if (checkboxes[i].type == 'checkbox') {
checkboxes[i].checked = false;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.