1, the problem background
There are several multiple selection boxes, select a few of them, get the selected values
2, the design results as shown in the following figure:
3. Design Source
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Let's share a piece of code. Methods for jquery operation checkbox (checked, canceled, value)
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" > <HTML> <HEAD> <TITLE> New document. nbsp;</title> <meta http-equiv= "Content-type" content= "text/html"; Charset=utf-8 "/> <script language=" javascript "src=" Http://www.cnjquery.com/demo/jquery.js "></script > <script language= "javascript" > <!--$ ("document. quot. Ready (function () {$ ("#btn1"). Click (function () {$ ("[name= ' checkbox ']"). attr ("Checked", ' true ');//Select All}) $ ("# Btn2 "). Click (function () {$ (" [name= ' checkbox '] "). Removeattr (" checked ");//Deselect All}) $ (" #btn3 "). Click (function () {$ (" [ Name= ' checkbox ']:even '). attr ("Checked", ' true ');//check all odd numbers}) $ ("#btn4"). Click (function () {$ ("[name= ' checkbox ']").
each (function () {if ($ (this). attr ("checked")) {$ (this). Removeattr ("checked");
} else {$ (this). attr ("Checked", ' true ');
}) $ ("#btn5"). Click (function () {var str= "";
$ ("[name= ' checkbox '][checked]"). each (the function () {str+=$ (this). Val () + "" R "N"; Alert ($ (this). Val ());
) alert (str); })//--> </SCRIPT> </HEAD> <BODY> <form name= "Form1" method= "post" action= "> <inp UT 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=" Btn5 "value=" selected All values in > <br> <input type= checkbox "name=" checkbox "value=" CheckBox1 "> CheckBox1 <input type=" checkb Ox "name=" checkbox "value=" CheckBox2 "> CheckBox2 <input type=" checkbox "name=" checkbox "value=" Checkbox3 "> Ch Eckbox3 <input type= "checkbox" name= checkbox "value=" Checkbox4 "> Checkbox4 <input type=" checkbox "Name=" Chec Kbox "value=" checkbox5 "> Checkbox5 <input type=" checkbox "name=" checkbox "value=" checkbox6 "> Checkbox6 <in Put type= "checkbox" name= "checkbox" value= "checkbox7" > checkbox7 <input type= "checkbox" name= "checkbox" Value= "CHeckbox8 "> Checkbox8 </form>
The above is a small set for everyone to share jquery get checkbox selected values, I hope to help.