Idea: 1, get the element. 2, with a For loop calendar array, the checkbox checked set to True to achieve the full selection, the checkbox checked set to False is not selected. 3, through if judgment, if checked is true to select the state, the checked is set to False, if the checked is false, the checked is set to true selected state.
JS Code
<script>window.onload=function(){ varCheckall=document.getelementbyid (' All '); varUncheck=document.getelementbyid (' uncheck '); varOthercheck=document.getelementbyid (' Othercheck '); varDiv=document.getelementbyid (' div '); varCheckbox=div.getelementsbytagname (' Input '); Checkall.onclick=function(){ for(i=0;i<checkbox.length;i++) {checkbox[i].checked=true; }; }; Uncheck.onclick=function(){ for(i=0;i<checkbox.length;i++) {checkbox[i].checked=false; }; }; Othercheck.onclick=function(){ for(i=0;i<checkbox.length;i++){ if(checkbox[i].checked==true) {checkbox[i].checked=false; } Else{checkbox[i].checked=true } }; }; }; </script>
HTML code
Select all: <input type= "button" id= "All" value= "Select All"/><br/>not selected<input type= "button" id= "uncheck" value= "not selected"/><br/>Inverse Selection<input type= "button" id= "Othercheck" value= "Reverse selection"/><br/> <div id= "div" > <input type= "checkbox"/& gt;<br/> <input type= "checkbox"/><br/> <input type= "checkbox"/><br/> <in Put type= "checkbox"/><br/> <input type= "checkbox"/><br/> <input type= "checkbox"/>& lt;br/> <input type= "checkbox"/><br/> <input type= "checkbox"/><br/> <input type= "checkbox"/><br/> <input type= "checkbox"/><br/> <input type= "checkbox"/><b R/> <input type= "checkbox"/><br/> <input type= "checkbox"/><br/> <input Type = "checkbox"/><br/> <input type= "checkbox"/><br/> <input type= "checkbox"/><br/& Gt <input type= "checkbox"/><br/> <input type= "checkbox"/><br/> <input type= "checkbox" /><BR/> <input type= "checkbox"/><br/> </div>
Run effect
This button is really ugly, personally like to use <input type= "Radio" >
JS implementation of the full selection, reverse selection, all do not select