12 Tips Summary of the jquery action check box (checkbox)

Source: Internet
Author: User

1, get a single checkbox check (three ways) $ ("Input:checkbox:checked"). val () or $ ("Input:[type= ' checkbox ']:checked"). val (); or $ ("Input:[name= ' ck ']:checked"). Val ();2, get multiple checkbox-checked items $ (' Input:checkbox '). each (function() {        if($( This). attr (' checked ') = =true) {alert ($ ( This). Val ()); }});3, set the first checkbox to a check value of $ (' Input:checkbox:first '). attr ("Checked", ' checked '); or $ (' Input:checkbox '). EQ (0). attr ("Checked", ' true ');4, set the last checkbox to a check value of $ (' Input:radio:last '). attr (' checked ', ' checked '); or $ (' Input:radio:last '). attr (' checked ', ' true ');5, set any checkbox based on the index value to a check value of $ (' Input:checkbox). EQ (index value). attr (' checked ', 'true‘), index value =0,1,2 .... or $ (' Input:radio '). Slice attr (' checked ', 'true‘) 6. Select multiple checkboxes and select the 1th and 2nd checkbox$ (' Input:radio '). Slice (0,2). attr (' checked ', 'true‘); 7. Set the checkbox to a value of $ ("Input:checkbox[value=' 1 ']. attr (' checked ', 'true‘); 8, delete value=1 checkbox$ ("Input:checkbox[value=' 1 ']. Remove (); 9, delete the first few checkbox$ ("Input:checkbox"). EQ (index value). Remove (); index value =0,1,2 .... If you delete the 3rd checkbox:$ ("Input: CheckBox "). EQ (2). Remove (), 10, Traverse 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);});

12 Tips Summary of the jquery action check box (checkbox)

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.