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 check 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:last '). attr (' checked ', ' checked ');
Or
$ (' Input:radio:last '). attr (' checked ', ' true ');
5. Set any checkbox to the selected value according to the index value
$ (' Input:checkbox). EQ (index value). attr (' checked ', ' true '); index value =0,1,2 ....
Or
$ (' Input:radio '). Slice. attr (' checked ', ' true ');
6. Select multiple checkboxes to select both 1th and 2nd checkboxes
$ (' Input:radio '). Slice (0,2). attr (' checked ', ' true ');
7. Set checkbox to selected value according to value
$ ("input:checkbox[value= ' 1 ']"). attr (' checked ', ' true ');
8. Delete value=1 checkbox
$ ("input:checkbox[value= ' 1 ']"). Remove ();
9. Delete the first few checkboxes
$ ("Input:checkbox"). EQ (index value). Remove (); index value =0,1,2 ....
To delete a 3rd checkbox:
$ ("Input:checkbox"). EQ (2). Remove ();
10. Traversal checkbox
$ (' Input:checkbox '). each (function (index, domele) {
Write code
});
11. Select All
$ (' Input:checkbox '). each (function () {
$ (this). attr (' checked ', true);
});
12. Cancel All Selection
$ (' Input:checkbox '). each (function () {
$ (this). attr (' checked ', false);
});