Copy Code code as follows:
<script language=javascript>
The first of these methods
function Selectall1 ()
{
var a = document.getElementsByTagName ("input");
if (a[0].checked==true) {
for (var i=0; i<a.length; i++)
if (A[i].type = = "checkbox") a[i].checked = false;
}
Else
{
for (var i=0; i<a.length; i++)
if (A[i].type = = "checkbox") a[i].checked = true;
}
}
The second method
function Selectall2 () {
var tform = document.forms[' Form1 '];
for (Var i=0;i<tform.length;i++)
{
var e = tform.elements[i];
if (E.type = "checkbox")
e.checked =!e.checked;
}
}
The third method, combined with both of these methods
function Selectall3 ()
{
var a = document.getElementsByTagName ("input");
for (var i=0; i<a.length; i++)
if (A[i].type = = "checkbox") a[i].checked =!a[i].checked;
}
Fourth method
function Selectall4 (ID) {//ID Distinguished
var tform=document.forms[' Form1 '];
for (Var i=0;i<tform.length;i++) {
var e=tform.elements[i];
if (e.type== "checkbox" && e.name==id) e.checked=!e.checked;
}
}
Fifth method
function SelectAll (theform,thename) {//theform specified form,thename is the Name property of the checkbox
var tform=document.forms[theform];
document.getElementById ("Thewen"). Value= ' reverse election ';
for (Var i=0;i<tform.length;i++) {
var e=tform.elements[i];
if (e.type== ' checkbox ' && e.name==thename) e.checked=!e.checked;
}
}
</script>
<form id= "Form1" Name= "Form1" method= "Post" action= "" >
<input type= "checkbox" name= "Sid" Value= "1"/>
<input name= "thes" type= "button" onclick= "Javascript:selectall3 ()" value= "Select All"/>
</form>
<script language=javascript>//First method function Selectall1 () {var a = document.getElementsByTagName ("input") ; if (a[0].checked==true) {for (var i=0 i<a.length; i++) if (A[i].type = "checkbox") a[i].checked = false; else {for (var i=0 i<a.length; i++) if (A[i].type = = "checkbox") a[i].checked = true; }//second method function Selectall2 () {var tform = document.forms[' Form1 ']; for (Var i=0;i<tform.length;i++) {var e = tform.elements[i]; if (E.type = = "checkbox") e.checked =!e.checked; }//Third method, combining the above two methods function Selectall3 () {var a = document.getElementsByTagName ("input"); for (var i=0 i<a.length; i++) if (A[i].type = = "checkbox") a[i].checked =!a[i].checked; The//Fourth method function Selectall4 (ID) {//ID differentiate var tform=document.forms[' Form1 '); for (Var i=0;i<tform.length;i++) {var e=tform.elements[i]; if (e.type== "checkbox" && e.name==id) e.checked=!e.checked; }//Fifth method function Selectall5 (theform,thename) {var tform=document.forms[theform]; document.getElementById ("Thewen"). Value= ' reverse election '; for (Var i=0;i<tform.length;i++) {var e=tform.elements[i]; if (e.type== ' checkbox ' && e.name==thename) e.checked=!e.checked; } </script> <form id= "Form1" Name= "Form1" method= "post" action= "> <input type=" checkbox "Name=" Sid "value=" 1 "/> <input type=" checkbox "name=" Sid "Value=" 2 "/> <input" checkbox "type=" Sid "Name=" 3 "value= Gt <input type= "checkbox" name= "Sid" Value= "4"/> <input name= "thes" button "type=" onclick= 1 () "value=" the first "/> <input name=" thes "type=" button "onclick=" Javascript:selectall2 () "Value=" "The second"/> <i Nput name= "thes" type= "button" onclick= "Javascript:selectall3 ()" value= "third"/> <input name= "thes" type= "button" onclick= "Javascript:selectall4 (' Sid ')" value= "fourth"/> <input name= "thes" type= "button" onclick= "Javascript:selectall5 (' Form1 ', ' Sid ')" value= "fifth kind"/> </form>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
PS: All of the above three methods can achieve effect, but if you want to implement (select All |), you need to add