实现checkbox的全选和取消
如果点击全选就把所有选项全选上,这个我们常用。。。
View Code
1 <script type="text/javascript"> 2 /*实现checkbox的全选和取消*/ 3 function selectAll(dom){ 4 var a = document.getElementsByName("select"); 5 if(dom.checked){ 6 for(i=0;i<a.length;i++){ 7 a[i].checked = true; 8 } 9 }else{ 10 for(i=0;i<a.length;i++){ 11 a[i].checked = false; 12 } 13 } 14 } 15 <body> 16 <fieldSet> 17 <legend style = "margin-left : 500px">个人爱好</legend> 18 <input type= "checkbox" onchange = "selectAll(this)"/>全选</br> 19 <input type = "checkbox" name = "select"/>苹果 20 <input type = "checkbox" name = "select"/>逛街 21 <input type = "checkbox" name = "select"/>跑步 22 <input type = "checkbox" name = "select"/>郊游 23 <input type = "checkbox" name = "select"/>葡萄 24 <input type = "checkbox" name = "select"/>哈密瓜 25 26 </fieldSet>
大家可以练习一下...