Jquery --- Select All or cancel all of the checkbox
Checkbox is an inevitable control in system development. Generally, multiple checkboxes are selected, all are selected, or all are canceled. Some time ago, I encountered the checkbox usage. A few days later, I would like to give some help to my friends who want to use the checkbox control.
Sometimes we need to click a checkbox control. When it is selected, all other checkboxes are selected, and then click it to deselect it. All other checkboxes are deselected. At this time, we can use the following code in the HTML or. jsp file to implement this function. The Code is as follows:
Select All
$(document).ready(function(){ $(#checkAll).click(function(){ if(this.checked) { $(input[name='checkbox']).each(function(){ this.checked=true; }); // $([name='checkbox']).attr(checked,'true'); } else { $(input[name='checkbox']).each(function(){ this.checked=false; }); //$([name='checkbox']).attr(checked,'false'); } }); });
If the check box checkbox is selected, How can I obtain the checkbook value of the selected check box?
0 1 2 3 4 5 6 7
Function jqchk () {// jquery obtains the check box value var chk_value = []; $ (input [name = test]: checked ). each (function () {chk_value.push ($ (this ). val () ;}); alert (chk_value.length = 0? 'You have not selected any content! ': Chk_value );}
The above are several common functions of the checkbox, hoping to help our friends.