12 tips for jquery operation check box (checkbox) _ jquery

Source: Internet
Author: User
This article mainly summarizes the 12 tips of the jquery check box (checkbox). If you need a friend, please refer to them and hope to help you. 1. Obtain the selected items of a single checkbox (three methods)
$ ("Input: checkbox: checked"). val ()
Or
$ ("Input: [type = 'checkbox']: checked"). val ();
Or
$ ("Input: [name = 'ck ']: checked"). val ();

2. Obtain multiple checkbox selected items
$ ('Input: checkbox'). each (function (){
If ($ (this). attr ('checked') = true ){
Alert ($ (this). val ());
}
});

3. Set the first checkbox to the selected value.
$ ('Input: checkbox: first '). attr ("checked", 'checked ');
Or
$ ('Input: checkbox'). eq (0). attr ("checked", 'true ');

4. Set the last checkbox as the selected value.
$ ('Input: radio: la'). attr ('checked', 'checked ');
Or
$ ('Input: radio: la'). attr ('checked', 'true ');

5. set any checkbox as the selected value based on the index value.
$ ('Input: checkbox). eq (index value). attr ('checked', 'true'); index value = 0, 1, 2 ....
Or
$ ('Input: radio '). slice (1, 2). attr ('checked', 'true ');

6. Select multiple checkboxes and select 1st and 2nd checkboxes at the same time.
$ ('Input: radio '). slice (). attr ('checked', 'true ');

7. Set checkbox as the selected Value based on the Value.
$ ("Input: checkbox [value = '1']"). attr ('checked', 'true ');

8. Delete the checkbox with Value = 1
$ ("Input: checkbox [value = '1']"). remove ();

9. Delete the number of checkpoints
$ ("Input: checkbox"). eq (index value). remove (); index value = 0, 1, 2 ....
For example, delete 3rd checkboxes:
$ ("Input: checkbox"). eq (2). remove ();

10. traverse the checkbox
$ ('Input: checkbox'). each (function (index, domEle ){
// Write code
});

11. Select All
$ ('Input: checkbox'). each (function (){
$ (This). attr ('checked', true );
});

12. deselect all
$ ('Input: checkbox'). each (function (){
$ (This). attr ('checked', false );
});

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.