jquery implementation of the full selection, inverse selection, all do not select, and so on, the following directly illustrated by examples. Set the page like the next set of check boxes and a few related buttons (select all, reverse, select all, etc.):
<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= >
<input type= "button" id= "Btn3" value= "anti-selection >
<input type=" button "id=" Btn4 "value=" Select All Odd ">
The complete code for implementing the related functionality is as follows:
$ (function () {
$ (' #btn1 '). Click (function () {//Select all
$ ("[name= ' Fruit ']"). attr (' checked ', ' true ');
});
$ (' #btn2 '). Click (function () {//All is not selected
$ ("[name= ' Fruit ']"). Removeattr (' checked ');
});
$ (' #btn3 '). Click (function () {//Reverse
$ ("[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!
The above is a small series of hard to clean up the code, is not easy to use, hope to help everyone.