Jquery obtains the checkbox, radio, and select values.

Source: Internet
Author: User
In html, checkbox, radio, and select are used frequently during website development. These three controls can be used to select values. How can we select these controls. This article describes how to use jquery to obtain the selected values of these controls. Jquery gets the radio selected value:

123

You can use either of the following methods:

$('input:radio:checked').val();$("input[type='radio']:checked").val();$("input[name='rd']:checked").val();

Jquery gets the selected select value:

      option1    option2    option3    option4  

Obtain the Value of the selected item:

$ ('Select # sel option: selected'). val (); or $ ('select # sel '). find ('option: selected'). val ();

Obtain the Text value of the selected item:

$ ('Select # seloption: selected'). text (); or $ ('select # sel '). find ('option: selected'). text ();

Obtain the index value of the selected item:

$('select#sel').get(0).selectedIndex;

Jquery gets the checkbox selected value:

checkbox1     checkbox2     checkbox3      

Obtain the selected items of a single checkbox:

$ ("Input: checkbox: checked "). val () or $ ("input: [type = 'checkbox']: checked "). val (); or $ ("input: [name = 'ck ']: checked "). val ();


Obtain multiple checkbox selected items:

$('input:checkbox').each(function() {     if ($(this).attr('checked') ==true) {         alert($(this).val());     } }); 

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.