1. Select All
$ ("#btn1"). Click (function() {$ ("input[name= ' checkbox ']"). attr ("Checked", "true"
2. Cancel all selection (all optional)
$ ("#btn2"). Click (function() {$ ("input[name= ' checkbox ']"). Removeattr ("Checked"
3. Select All Odd
$ ("#btn3"). Click (function() {$ ("input[name= ' checkbox ']:odd"). attr ("Checked", "true"
4. Select All even
$ ("#btn6"). Click (function() {$ ("input[name= ' checkbox ']:even"). attr ("Checked", "true"
5. Counter-election
$ ("#btn4"). Click (function() {$ ("input[name= ' checkbox ']"). each (thefunctionif ($ (this). attr (" Checked ")) {$ (this). Removeattr (" checked "else {$ (this). attr (" Checked "," true "
Or
$ ("#invert"). Click (function() { $ ("#ruleMessage [name= ' Delmoduleid ']:checkbox"). each (function (i,o) { $ (o). attr ("Checked",!$ (o). attr ("checked")); } );
6. Get the value of the selection
var aa= ""; $ ("#btn5"). Click (function() {$ ("input[name= ' checkbox ']:checkbox:checked"). each ( function() {aa+=$ ( This
7. Traverse the selected item
$ ("input[type=checkbox][checked]"). each (function// Because the check box is generally selected for more than one, so you can loop output alert ($ (This
8. Example
<Htmlxmlns= "Http://www.w3.org/1999/xhtml"><HeadRunat= "Server"><Title> Untitled Page</Title><ScriptSrc= "Js/jquery-1.6.min.js"Type= "Text/javascript"></Script><ScriptType= "Text/javascript">JQuery (function($) {//Select All$("#btn1"). Click (function(){ $("Input[name= ' checkbox ']"). attr ("Checked","True"); })//Cancel Select All$("#btn2"). Click (function(){ $("Input[name= ' checkbox ']"). Removeattr ("Checked"); })//Select All Cardinality$("#btn3"). Click (function(){ $("Input[name= ' checkbox ']:even"). attr ("Checked","True"); })//Select all even$("#btn6"). Click (function(){ $("Input[name= ' checkbox ']:odd"). attr ("Checked","True"); })//Inverse selection$("#btn4"). Click (function(){ $("Input[name= ' checkbox ']"). each (function(){If($(This). attr ("Checked")) { $(This). Removeattr ("Checked"); }Else{ $(This). attr ("Checked","True"); } }) })//Perhaps the value of the selected itemVarAa=""; $("#btn5"). Click (function(){ $("Input[name= ' checkbox ']:checkbox:checked"). each (function() {AA+=$(This). Val ()}) document.write (AA); }) })</Script></Head><Body><FormId= "Form1"Runat= "Server"><Div><Input type= "button" id= "BTN1" value= "Select All" > <input type= "button" id= "Btn2" value= "deselect All" > <input type= "button" Id= "Btn3" value= "Select All odd" > <input type= "button" id= "Btn6" value= "Select all even" > <input type= "button" id= "Btn4" value= "Reverse Selection" > <input type= "button" id= "Btn5" value= "Get All selected Values" > <br> <input type= "checkbox" Name= " CheckBox "value=" CheckBox1 "> CheckBox1 <input type=" checkbox "name=" checkbox "value=" CheckBox2 "> CheckBox2 <input type= "checkbox" name= "checkbox" value= "Checkbox3" > Checkbox3 <input type= "checkbox" Name= "checkbox" Value= "Checkbox4" > Checkbox4 <input type= "checkbox" name= "checkbox" value= "Checkbox5" > Checkbox5 <input type= "checkbox" name= "checkbox" value= "checkbox6" > Checkbox6 <input type= "checkbox" name= "checkbox" Value= " CHECKBOX7 "> checkbox7 <input type=" checkbox "name=" checkbox "value=" checkbox8 "> Checkbox8 </div> </ Form> </body>
9.
jquery checkbox Related Operations-Select all, deselect, and get all selected checkboxes