Summary of operations related to jquery checkbox, jquerycheckbox
Operations related to jquery checkbox-select all, reselect, and retrieve all selected checkboxes
1. Select All
$("#btn1").click(function(){ $("input[name='checkbox']").attr("checked","true"); })
2. Cancel all selections (none)
$("#btn2").click(function(){ $("input[name='checkbox']").removeAttr("checked"); })
3. Select All odd numbers
$("#btn3").click(function(){ $("input[name='checkbox']:odd").attr("checked","true"); })
4. Select all even numbers
$("#btn6").click(function(){ $("input[name='checkbox']:even").attr("checked","true"); })
5. Invert Selection
$("#btn4").click(function(){ $("input[name='checkbox']").each(function(){ if($(this).attr("checked")) { $(this).removeAttr("checked"); } else { $(this).attr("checked","true"); } }) })
Or
$("#invert").click(function(){ $("#ruleMessage [name='delModuleID']:checkbox").each(function(i,o){ $(o).attr("checked",!$(o).attr("checked")); }); });
6. Obtain the value of the selected item
var aa=""; $("#btn5").click(function(){ $("input[name='checkbox']:checkbox:checked").each(function(){ aa+=$(this).val() }) document.write(aa); }) })
7. Traverse selected items
$ ("Input [type = checkbox] [checked]"). each (function () {// Since multiple check boxes are selected, You can output alert ($ (this) cyclically ). val ());});
8. Example
<Html xmlns = "http://www.w3.org/1999/xhtml">
9,
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!