Select All check boxes based on jQuery. Select All jquery check boxes.
This code is selected from a large number of jQuery check box function code. The code used in my project is shared here.
JQuery code:
Copy codeThe Code is as follows:
$ (Function (){
$ ("# CheckedAll"). click (function (){
$ ('[Name = items]: checkbox'). attr ('checked', true );
});
$ ("# CheckedNo"). click (function (){
$ ('[Name = items]: checkbox'). attr ('checked', false );
});
$ ("# CheckedRev"). click (function (){
$ ('[Name = items]: checkbox'). each (function (){
// $ (This). attr ('checked ',! $ (This). attr ('checked '));
This. checked =! This. checked;
});
});
$ ("# Send"). click (function (){
Var str = "you selected: \ r \ n ";
$ ('[Name = items]: checkbox: checked'). each (function (){
Str + = $ (this). val () + "\ r \ n ";
});
Alert (str );
});
});
HTML code:
Copy codeThe Code is as follows:
What kind of sports do you like? <Br>
<Input type = "checkbox" name = "items" value = ""/> football
<Input type = "checkbox" name = "items" value = "basketball"/> basketball
<Input type = "checkbox" name = "items" value = "badminton"/> Badminton
<Input type = "checkbox" name = "items" value = ""/> Table Tennis <br>
<Input type = "button" id = "checkedAll" value = "select all"/>
<Input type = "button" id = "checkedNo" value = "NONE"/>
<Input type = "button" id = "checkedRev" value = ""/>
<Input type = "button" id = "send" value = "Submit"/>
It is not very convenient for our friends to use it. This is also very helpful to everyone.