The checkbox for jQuery operation input

Source: Internet
Author: User

JQuery operation input checkbox one Piece

HTML Checklist:

<input type= "checkbox" name= "Hobby" value= "Baseball" > Baseball <input type= "checkbox" name= "Hobby" value= "Table tennis" > table tennis < Input type= "checkbox" name= "Hobby" value= "Badminton" > Badminton <input type= "checkbox" name= "Hobby" value= "basketball" > Basketball < Input type= "checkbox" name= "hobby" value= "soccer" > Soccer <input type= "checkbox" Name= "Checkall" value= "" > select All


1. Bind the event to each item:

$ ("[name= ' Hobby ']:checkbox"). On (' click ', Function () {    alert (the This). Val ());});

2. Get the selected item:

$ ("[name= ' Checkall ']:checkbox"). On (' click ', Function () {    var val = ';    $ ("[name= ' Hobby ']:checkbox"). each (function () {        if ($ (). attr (' checked ')) {            val + = $ (this). Val () + ', ';        }    });    val = val.length > 0? Val.substr (0, val.length-1): ";    Alert (val);});

3, select All/Not selected

Click on each item to trigger $ ("[name= ' Hobby ']:checkbox"). On (' click ', Function () {    var $items = $ ("[name= ' hobby ']:checkbox ');    $ ("[name= ' Checkall ']:checkbox"). attr (' checked ', $items. length = = $items. Filter ("[Name= ' hobby ']:checked '). length);}); /Click the Select All Trigger $ ("[name= ' Checkall ']:checkbox"). On (' click ', Function () {    $ ("[name= ' hobby ']:checkbox ')." attr (' checked ') , this.checked);});

Maybe tidy up constantly updated ...

This article originates from CSDN, please indicate the source.

Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

The checkbox for jQuery operation input

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.