<script> <BR>//第一种方法 <BR>function selectall1() <BR>{ <BR> var a = document.getElementsByTagName("input"); <BR> if(a[0].checked==true){ <BR> for (var i=0; i<a.length; i++) <BR> if (a[i].type == "checkbox") a[i].checked = false; <BR> } <BR> else <BR> { <BR> for (var i=0; i<a.length; i++) <BR> if (a[i].type == "checkbox") a[i].checked = true; <BR> } <BR>} <br><br>//第二种方法 <br><br>function selectall2() { <BR> var tform = document.forms['form1']; <BR> for (var i=0;i<tform.length;i++) <BR> { <BR> var e = tform.elements[i]; <BR> if (e.type == "checkbox") <BR> e.checked = !e.checked; <BR> } <BR>} <br><br>//第三种方法,结合上述两种方法 <BR>function selectall3() <BR>{ <BR> var a = document.getElementsByTagName("input"); <BR> for (var i=0; i<a.length; i++) <BR> if (a[i].type == "checkbox") a[i].checked =!a[i].checked; <BR> } <BR>//第四种方法 <BR>function selectall4(id){ //用id区分 <BR>var tform=document.forms['form1']; <BR>for(var i=0;i<tform.length;i++){ <BR>var e=tform.elements[i]; <BR>if(e.type=="checkbox" && e.name==id) e.checked=!e.checked; <BR>} <BR>} <BR>//第五种方法 <BR>function selectall(theform,thename){ //theform指定的form,thename是checkbox的name属性 <BR>var tform=document.forms[theform]; <BR>document.getElementById("thewen").value='反选'; <BR>for(var i=0;i<tform.length;i++){ <BR> var e=tform.elements[i]; <BR> if(e.type=='checkbox' && e.name==thename)e.checked=!e.checked; <BR> } <BR>} <BR></script>
PS:上述三种方法,都可实现效果,但如果想实现(全选|反选),就需要根据要求添加
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn