jquery checkbox Related Operations-Select all, deselect, and get all selected checkboxes

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.