Home > front end >  How can I achieve both the checkbox selection button
How can I achieve both the checkbox selection button

Time:09-29

 & 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; i Checkson [I]. Checked=true; }}
The else {
for(var i=0; i Checkson [I]. Checked=false; }}
}
</script>

CodePudding user response:

A not line? Judge checkAll value is used to judge, all selected all false is not true

CodePudding 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; i Checkson [I]. Checked=true; }}
The else {
for(var i=0; i Checkson [I]. Checked=false; }}
}
</script>

CodePudding user response:

Brother badly, thanks
  • Related