This article mainly introduces the summary of JQueryCheckBox (check box) operation methods, this article describes how to obtain a single checkbox selected item, obtain multiple checkbox selected items, set the first checkbox as the selected value, and set the last checkbox as the selected value. For more information, see
1. obtain the selected items of a single checkbox (three methods ):
The code is as follows:
$ ("Input: checkbox: checked"). val ()
Or
The code is as follows:
$ ("Input: [type = 'checkbox']: checked"). val ();
Or
The code is as follows:
$ ("Input: [name = 'CK ']: checked"). val ();
2. obtain multiple checkbox selected items:
The code is as follows:
$ ('Input: checkbox'). each (function (){
If ($ (this). attr ('checked') = true ){
Alert ($ (this). val ());
}
});
Or
The code is as follows:
('Input: checkbox'). map (function (){
Return (this). val ();
}). Get (). join (',');
3. set the first checkbox as the selected value:
The code is as follows:
$ ('Input: checkbox: first '). attr ("checked", 'checked ');
Or
The code is as follows:
$ ('Input: checkbox'). eq (0). attr ("checked", 'true ');
4. set the last checkbox as the selected value:
The code is as follows:
$ ('Input: radio: LA'). attr ('checked', 'checked ');
Or
The code is as follows:
$ ('Input: radio: LA'). attr ('checked', 'true ');
5. set any checkbox as the selected value based on the index value:
The code is as follows:
$ ('Input: checkbox). eq (index value). attr ('checked', 'true'); index value = 0, 1, 2 ....
Or
The code is as follows:
$ ('Input: radio '). slice (1, 2). attr ('checked', 'true ');
6. select multiple checkboxes:
Select 1st and 2nd checkboxes at the same time:
The code is as follows:
$ ('Input: radio '). slice (). attr ('checked', 'true ');
7. set checkbox as the selected Value based on the Value:
The code is as follows:
$ ("Input: checkbox [value = '1']"). attr ('checked', 'true ');
8. delete the checkbox with Value = 1:
The code is as follows:
$ ("Input: checkbox [value = '1']"). remove ();
9. delete the following checkboxes:
The code is as follows:
$ ("Input: checkbox"). eq (index value). remove (); index value = 0, 1, 2 ....
For example, delete 3rd checkboxes:
The code is as follows:
$ ("Input: checkbox"). eq (2). remove ();
10. traverse the checkbox:
The code is as follows:
$ ('Input: checkbox'). each (function (index, domEle ){
// Write code
});
11. Select All
The code is as follows:
$ ('Input: checkbox'). each (function (){
$ (This). attr ('checked', true );
});
12. deselect all options:
The code is as follows:
$ ('Input: checkbox'). each (function (){
$ (This). attr ('checked', false );
});