Set the page like the next set of check boxes and a few related buttons (select all, reverse, select all, etc.):
Copy Code code as follows:
<input type= "checkbox" name= "fruit" value= "apple"/> Apples
<input type= "checkbox" name= "fruit" value= "orange"/> Orange
<input type= "checkbox" name= "fruit" value= "banana"/> Banana
<input type= "checkbox" name= "fruit" value= "grape"/> Grapes
<input type= "button" id= "BTN1" value= "Select All" >
<input type= "button" id= "BTN2" value= "all do not choose" >
<input type= "button" id= "Btn3" value= "anti-selection" >
<input type= "button" id= "Btn4" value= "Select All Odd" >
<input type= "button" id= "Btn5" value= "Get All values selected" >
The complete code for implementing the related functionality is as follows:
Copy Code code as follows:
$ (function () {
$ (' #btn1 '). Click (function () {//All selected
$ ("[name= ' Fruit ']"). attr (' checked ', ' true ');
});
$ (' #btn2 '). Click (function () {//All not selected
$ ("[name= ' Fruit ']"). Removeattr (' checked ');
});
$ (' #btn3 '). Click (function () {//anti-election
$ ("[name= ' Fruit ']"). each (function () {
if ($ (this). attr (' checked ')) {
$ (this). Removeattr (' checked ');
}else{
$ (this). attr (' checked ', ' true ');
}
})
});
$ ("#btn4"). Click (function () {//Select all odd
$ ("[name= ' Fruit ']:even"). attr (' checked ', ' true ');
})
$ ("#btn5"). Click (function () {//Get the value of all selected options
var checkval= ';
$ ("[name= ' Fruit '][checked]"). each (function () {
checkval+=$ (This). Val () + ', ';
})
alert (checkval);
})
});
Note that jquery packets must be introduced before using jquery!