Copy codeThe Code is as follows:
<Script language = javascript>
// Method 1
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;
}
}
// Method 2
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 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;
}
// Method 4
Function selectall4 (id) {// differentiate by id
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;
}
}
// Method 5
Function selectall (theform, thename) {// form specified by theform, thename is the name attribute of checkbox
Var tform = document. forms [theform];
Document. getElementById ("thewen"). value = 'select ';
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> // function selectall1 () {var a = document. getElementsByTagName ("input"); if (a [0]. checked = true) {for (var I = 0; I
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
PS: The above three methods can achieve the effect, but if you want to achieve (select all | select inverse), you need to add as required