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