How to obtain the Radio element value in jQuery _ jquery-js tutorial

Source: Internet
Author: User
This article introduces how to obtain the Radio element value in jQuery. If you need it, you can refer to it and find that the JavaScript code you have written has an error running in FireFox. The reason is very depressing, when obtaining the value of a Radio element, only undefind is required.
Google, most of them are the same as what I use

The Code is as follows:


Var value = $ ("input [name = 'radio1'] [type = 'radio'] [checked]"). val ();


This statement is successfully tested in IE and Safari (3.2), but cannot be selected in FireFox or Chrome.
Read the manual carefully and find the list of "form object attributes. Is there a special method for determining the attributes of a form object? Change the code

The Code is as follows:


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


All tests passed in IE, FireFox, Chrome, and Safari (3.2.
By the way, I tested the select element. The method in the manual is similar to the one I often use. The correct value can be obtained in the preceding browsers.

The Code is as follows:


Var value1 = $ ("select"). val (); var value2 = $ ("select option: selected"). val ();


I tested it in jQuery 1.32. You can try it.
Related Article

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.