Not to mention, you can directly copy the code and use it directly.
[Html]
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> untitled document </title>
</Head>
<Script>
Function selectAllNullorReserve (obj, type ){
If (obj! = Null & obj! = ""){
If (document. getElementsByName (obj )! = Undefined & document. getElementsByName (obj). length> 0) {// The getElementsByName function searches for objects by name and returns an array.
Var userids = document. getElementsByName (obj );
If (type = "select all "){
For (var I = 0; I <userids. length; I ++ ){
If (userids [I]. checked = false ){
Userids [I]. checked = true;
}
}
} Else if (type = "NONE "){
For (var I = 0; I <userids. length; I ++ ){
If (userids [I]. checked = true ){
Userids [I]. checked = false;
}
}
} Else if (type = "invert "){
For (var I = 0; I <userids. length; I ++ ){
If (userids [I]. checked = true ){
Userids [I]. checked = false;
} Else {
Userids [I]. checked = true;
}
}
}
}
}
}
</Script>
<Body>
<Form>
<Input name = "userid" type = "checkbox" value = "1"/>
<Input name = "userid" type = "checkbox" value = "2"/>
<Input name = "userid" type = "checkbox" value = "3"/>
<Input name = "userid" type = "checkbox" value = "4"/>
<Input name = "userid" type = "checkbox" value = "5"/>
<Input name = "userid" type = "checkbox" value = "6"/>
<Br/>
<Input type = "button" value = "select all" onclick = "selectAllNullorReserve ('userid', 'select all ');"/>
<Br/>
<Input type = "button" value = "do not select all" onclick = "selectAllNullorReserve ('userid', 'Do not select all ');"/>
<Br/>
<Input type = "button" value = "invert" onclick = "selectAllNullorReserve ('userid', 'select');"/>
</Form>
</Body>
</Html>
From the wolinxuebin Column