& lt; Input the id="check" onclick="checkAll ()" type="checkbox" name="checkbox1" value="https://bbs.csdn.net/topics/checkbox"/& gt;
<script>
The function checkAll () {
Var checked=document. GetElementById (" check ") checked;
Var checkson=document. GetElementsByName (" checkbox2 ");
If (checked) {
for(var i=0; iCheckson [I]. Checked=true; }}
The else {
for(var i=0; iCheckson [I]. Checked=false; }}
}
</script>
CodePudding user response:
A not line? Judge checkAll value is used to judge, all selected all false is not trueCodePudding user response:
Like this:CodePudding user response:
& lt; Input the id="check1" onclick="checkAll (enclosing checked)" type="checkbox" name="checkbox1" value="https://bbs.csdn.net/topics/checkbox"/& gt;
<script>
The function checkAll (checked) {
Document. The getElementById (" check1 "). Checked=checked;
Document. The getElementById (" check2 "). Checked=checked;
Var checkson=document. GetElementsByName (" checkbox2 ");
If (checked) {
for(var i=0; iCheckson [I]. Checked=true; }}
The else {
for(var i=0; iCheckson [I]. Checked=false; }}
}
</script>
CodePudding user response:
Brother badly, thanks