Summary of relevant operations of jquery checkbox _jquery

Source: Internet
Author: User

Related Operations for jquery checkbox-Select all, reverse, and get all selected checkbox

1. Select All

$ ("#btn1"). Click (function () { 
$ ("Input[name= ' checkbox ']"). attr ("Checked", "true"); 
}) 
 

2, cancel all election (all do not choose)

$ ("#btn2"). Click (function () { 
$ ("Input[name= ' checkbox ']"). Removeattr ("checked"); 
 
 

 

3. Select all odd numbers

$ ("#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. Anti-election

$ ("#btn4"). Click (function () { 
$ ("Input[name= ' checkbox ']"). each (function () { 
if ($ (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 selected item

var aa= ""; 
$ ("#btn5"). Click (function () { 
$ (' input[name= ' checkbox ']:checkbox:checked '). each (function () { 
aa+=$ ( This). val () 
}) 
document.write (AA); 
}) 

7. Traverse Selected Items

$ ("input[type=checkbox][checked]"). each (function () {
 //Because the check box is generally selected for more than one, you can loop out 
 alert ($ (this). Val ()); 
 

8. Examples

 

9. Effect Drawing

Thank you for reading, I hope to help you, thank you for your support for this site!

Related Article

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.