Jquery implements the functions such as full selection, reverse selection, and no selection. The following example describes the functions. For more information, see the following set of check boxes and related buttons on the page, all are not selected ):
The Code is as follows:
Apple
Orange
Bananas
Grape
The complete code for implementing the relevant functions is as follows:
The Code is as follows:
$ (Function (){
$ ('# Btn1'). click (function () {// select all
$ ("[Name = 'fruit']"). attr ('checked', 'true ');
});
$ ('# Btn2'). click (function () {// none
$ ("[Name = 'fruit']"). removeAttr ('checked ');
});
$ ('# Btn3'). click (function () {// reselect
$ ("[Name = 'fruit']"). each (function (){
If ($ (this). attr ('checked ')){
$ (This). removeAttr ('checked ');
} Else {
$ (This). attr ('checked', 'true ');
}
})
});
$ ("# Btn4"). click (function () {// select all odd numbers
$ ("[Name = 'fruit']: even"). attr ('checked', 'true ');
})
$ ("# Btn5"). click (function () {// obtain the values of all selected options
Var checkVal = '';
$ ("[Name = 'fruit'] [checked]"). each (function (){
CheckVal + = $ (this). val () + ',';
})
Alert (checkVal );
})
});
Before using jquery, you must introduce the jquery package!