Copy Code code as follows:
<!--
$ ("document"). Ready (function () {
$ ("#btn1"). Click (function () {
$ ("[name= ' checkbox ']"). attr ("Checked", ' true ');/select All
})
$ ("#btn2"). Click (function () {
$ ("[name= ' checkbox ']"). Removeattr ("checked");/Cancel All selection
})
$ ("#btn3"). Click (function () {
$ ("[name= ' checkbox ']:even"). attr ("Checked", ' true ');//Select All odd numbers
})
$ ("#btn4"). Click (function () {
$ ("[name= ' checkbox ']"). each (function () {//anti-election
if ($ (this). attr ("checked")) {
$ (this). Removeattr ("checked");
}
else{
$ (this). attr ("Checked", ' true ');
}
})
})
$ ("#btn5"). Click (function () {//Output selected value
var str= "";
$ ("[name= ' checkbox '][checked]"). each (function () {
str+=$ (This). Val () + "\ r \ n";
Alert ($ (this). Val ());
})
alert (str);
})
})
-->
which
Copy Code code as follows:
$ ("[name= ' checkbox '][checked]"). each (function () {
str+=$ (This). Val () + "\ r \ n"; Alert ($ (this). Val ());
})
This part of the code in Firefox does not work, after searching the internet, found a way to use the normal, as follows:
Copy Code code as follows:
$ ("[name= ' checkbox ']:checked"). each (function () {
str+=$ (This). Val () + "\ r \ n"; Alert ($ (this). Val ());
})
That is, use the $ ("[name= ' checkbox ']:checked") method to properly access the collection of selected controls for the Radio/checkbox group
after running, you need to refresh the next
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/> <title>louis-blog >> jQuery operation on checkbox </title> <script type= ' text/ JavaScript ' src= ' http://img.jb51.net/jslib/jquery/jquery.js ' ></script> <script language= ' JavaScript ' > <!--$ ("document"). Ready (function () {$ (#btn1). Click (function () {$ ("[name= ' checkbox ']"). attr ("Checked", ' True ') $ (' #btn2 '). Click (function () {$ ("[name= ' checkbox ']"). Removeattr ("checked");/deselect All}) $ ("#btn3"). Click (function () {$ (' [name= ' checkbox ']:even '). attr ("Checked", ' true ');//Select All odd Numbers}) $ ("#btn4"). Click (function () {$ ("[name= ' checkbox ']. each (function () {//reverse-Select if ($ (this). attr ("checked")) {$ (this). Removeattr ("checked"); } else{$ (this). attr ("Checked", ' true '); }}) $ ("#btn5"). Click (function () {//Output selected value var str= ""; $ ("[name= ' checkbox '][checked]"). each (function () {str+=$ (this). Val () + "\ r \ n"; Alert ($ (this). Val ()); ) alert (str); })--> </SCRIPT> </HEAD> <body > <div > <form name= "Form1" method= "Post" action= "" > <input type= "button" id= "BTN1" value= "Select All" > <input type= "button" id= "Btn2" value= "deselect All" > <input type = "button" id= "Btn3" value= "Select All odd" > <input type= "button" id= "Btn4" value= "reverse select > <input type=" button "id=" btn 5 "value=" to get all selected values "> <br><br> <input type=" checkbox "name= checkbox" value= "CheckBox1" > CheckBox1 <input type= "checkbox" name= "checkbox" value= "CheckBox2" > CheckBox2 <input type= "checkbox" Name= "ch Eckbox "value=" Checkbox3 "> Checkbox3 <input type=" checkbox "name=" checkbox "value=" Checkbox4 "> Checkbox4 < Input type= "checkbox" name= "checkbox" value= "Checkbox5" > Checkbox5 <input type= "checkbox" name= "checkbox" value= The checkBox6 "> checkbox6 </form> </div> </body> </HTML>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Get the selected value in the checkbox group in jquery
Copy Code code as follows:
var SelectText;
$ (": checkbox[name=yourcheckname]:checked"). each (function () {
selecttext+=$ (This). Val () + ', ';
})