The layout is as follows:
<p ><input type= "checkbox" id= "Che1"/> Select all </p>
<DivID= "Div1"> <inputtype= "checkbox" /><BR/> <inputtype= "checkbox" /><BR/> <inputtype= "checkbox" /><BR/> <inputtype= "checkbox" /><BR/> <inputtype= "checkbox" /><BR/> <inputtype= "checkbox" /><BR/> <inputtype= "checkbox" /><BR/> <inputtype= "checkbox" /><BR/> <inputtype= "checkbox" /><BR/> <inputtype= "checkbox" /><BR/></Div>
JavaScript is as follows:
<script type= "Text/javascript" >window.onload=function() {Xuanzhe (); } functionXuanzhe ()//define function {varOche1=document.getelementbyid (' Che1 ');//Get Che1varOdiv1=document.getelementbyid (' Div1 '). getElementsByTagName (' input '));//Get all input Oche1.onclick in Div=function()//define the CHE1 mouse click event { for(vari=0;i<odiv1.length;i++) { if(che1.checked==true) {odiv1[i].checked=true; } Else{odiv1[i].checked=false; } } }; }</script>
Can realize checkbox Select All Function! This feature is widely used in Web pages!
JS Beginner-Enable CheckBox Select All function