Use jquery to get the value of the check box for a selected checkbox

Source: Internet
Author: User
Tags javascript array

Use jquery to get the value of the check box for the selected checkbox:
The checkbox is an important form element that is used in a number of multiple choices, and the following is an example of how to get the values of all the selected items in the check box, in order to bring some help to a friend who needs it.
The code is as follows:

<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metaname= "Author"content= "http://www.softwhy.com/" /><title>Ant Tribe</title><Scripttype= "Text/javascript"src= "Mytest/jquery/jquery-1.8.3.js"></Script><Scripttype= "Text/javascript"> $(function(){   varTheArray=[]; $("#btn"). Click (function(){     $("input[name=ckb]:checked"). each (function() {Thearray.push ($ ( This). Val ());    });  alert (TheArray); })}) </Script></Head><Body><Div>  <inputtype= "checkbox"name= "CKB"value= "Ant Tribe One"/>Ant Tribe one<inputtype= "checkbox"name= "CKB"value= "Ant Tribe II"/>Ant Tribe two<inputtype= "checkbox"name= "CKB"value= "Ant Tribe three"/>Ant Tribe three<inputtype= "button"ID= "BTN"value= "Take value"/></Div></Body></HTML>

The above code is very simple here is not more introduction, you can see the relevant reading.
Related reading:
The 1.click event can be found in the Click event section of jquery .
The 2.each () function can refer to the each () method section of jquery .
The 3.push () function can refer to the section of the push () method of the JavaScript array object .
The 4.val () function can be found in the section of the Val () method of jquery .

The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=12403

For more information, refer to: http://www.softwhy.com/jquery/

Use jquery to get the value of the check box for a selected checkbox

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.