jquery Gets the value of the checkbox selected _jquery

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.