There are many ways to get the value of a check box. This article will show you how jquery gets the value of a check box. Do not miss it if you are interested.
The Code is as follows:
JS to obtain the selected value of the check box
0
1
2
3
4
5
6
7
JS Code
The Code is as follows:
Other operations on the checkbox
1. Select All
2. Cancel all selections
3. Select All odd numbers
4. Invert Selection
5. Obtain all selected values
Js Code
The Code is as follows:
$ ("Document"). ready (function (){
$ ("# Btn1"). click (function (){
$ ("[Name = 'checkbox']"). attr ("checked", 'true'); // select all
})
$ ("# Btn2"). click (function (){
$ ("[Name = 'checkbox']"). removeAttr ("checked"); // cancel all
})
$ ("# Btn3"). click (function (){
$ ("[Name = 'checkbox']: even"). attr ("checked", 'true'); // select all odd numbers
})
$ ("# Btn4"). click (function (){
$ ("[Name = 'checkbox']"). each (function () {// reselect
If ($ (this). attr ("checked ")){
$ (This). removeAttr ("checked ");
}
Else {
$ (This). attr ("checked", 'true ');
}
})
})
$ ("# Btn5"). click (function () {// output the selected value
Var str = "";
$ ("[Name = 'checkbox'] [checked]"). each (function (){
Str + = $ (this). val () + "/r/n ";
// Alert ($ (this). val ());
})
Alert (str );
})
})
Html code:
The Code is as follows:
Louis-blog> jQuery operations on checkbox