JQuery performs the following operations on the checkbox:
Copy to ClipboardReference: [www.bkjia.com] <! --
$ ("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 );
})
})
-->
Where
Copy to ClipboardReference: [www.bkjia.com] $ ("[name = 'checkbox'] [checked]"). each (function (){
Str + = $ (this). val () + "\ r \ n ";
// Alert ($ (this). val ());
})
This part of the Code does not work properly in FireFox. After searching on the Internet, you can find a method that can be used normally, as shown below:
Copy to ClipboardReference: [www.bkjia.com] $ ("[name = 'checkbox']: checked"). each (function (){
Str + = $ (this). val () + "\ r \ n ";
// Alert ($ (this). val ());
})
That is, you can use $ ("[name = 'checkbox']: checked") to obtain the set of selected controls in the radio/checkbox group.