12 tips for jquery operation check box (checkbox), jquerycheckbox
12 tips for jquery operation check box (checkbox.
1. Obtain a single checkbox selected item (three methods) $ ("input: checkbox: checked "). val () or $ ("input: [type = 'checkbox']: checked "). val (); or $ ("input: [name = 'ck ']: checked "). val (); 2. Get multiple checkbox selected 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 to the selected value $ ('input: radio: la '). attr ('checked', 'checked'); or $ ('input: radio: lae '). attr ('checked', 'true'); 5. set any checkbox as the selected value based on the index value $ ('input: checkbox ). eq (index value ). attr ('checked', 'true'); index value = 0, 1, 2 .... or $ ('input: radio '). slice (1, 2 ). attr ('checked', 'true'); 6. Select 1st and 2nd checkboxes at the same time ('input: radio ') for multiple checkboxes '). slice (0, 2 ). attr ('checked', 'true'); 7. Set checkbox as the selected Value based on the value $ ("input: checkbox [Value = '1']"). attr ('checked', 'true'); 8. Delete the checkbox $ ("input: checkbox [Value = '1']") of value = 1. remove (); 9. Delete the checkbox $ ("input: checkbox "). eq (index value ). remove (); index value = 0, 1, 2 .... for example, delete 3rd checkboxes: $ ("input: checkbox "). eq (2 ). remove (); 10. Traverse checkbox $ ('input: checkbox '). each (function (index, domEle) {// write code}); 11. Select $ ('input: checkbox '). each (function () {$ (this ). attr ('checked', true) ;}); 12. deselect $ ('input: checkbox') for all '). each (function () {$ (this ). attr ('checked', false );});