Directly add the code.
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ptml xmlns = "http://www.w3.org/1999/xhtml"> <pead runat = "server"> <title> Index </title> </pead> <body> <input id = "CheckAll" type = "checkbox"/> select <input name = "subBox" type = "checkbox" /> 1 <input name = "subBox" type = "checkbox"/> 2 <input name = "subBox" type = "checkbox"/> 3 <input name = "subBox" type = "checkbox"/> 4 </body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
The following code is comprehensive and is implemented based on the js control principle.
Copy codeThe Code is as follows:
<Script src = "http://img.jb51.net/jslib/jquery/jquery14.js"> </script>
<Script type = "text/javascript">
// Select all
Function CheckedAll (){
$ (': Checkbox'). attr ('checked', 'checked ');
}
// None
Function CheckedNo (){
$ (': Checkbox'). attr ('checked ','');
}
// Invert Selection
Function CheckedRev (){
Var arr = $ (': checkbox ');
For (var I = 0; I <arr. length; I ++ ){
Arr [I]. checked =! Arr [I]. checked;
}
}
</Script>
<Body>
<Div>
<Input id = "CheckAll" type = "checkbox"/>
<Input name = "subBox" type = "checkbox"/>
<Input name = "subBox" type = "checkbox"/>
<Input name = "subBox" type = "checkbox"/>
<Input name = "subBox" type = "checkbox"/>
</Div>
<Input type = "button" name = "btnCheckedAll" value = "select all" onclick = "javascript: CheckedAll ();"/>
<Input type = "button" name = "btnCheckedNo" value = "NONE" onclick = "javascript: CheckedNo ();"/>
<Input type = "button" name = "btnCheckedRev" value = "Reversed" onclick = "javascript: CheckedRev ();"/>
</Body>