Methods for obtaining radio element values in jquery _jquery

Source: Internet
Author: User
Also found that their own JavaScript code in Firefox run under the error, the reason is very depressed, in the acquisition of a radio element of the value of the time only to get the undefind.
Google a bit, most of the way I used is the same
Copy Code code as follows:

var value = $ ("input[name= ' Radio1 '][type= ' Radio '][checked]"). Val ();

This sentence in IE, Safari (3.2) under the test, but in Firefox, Chrome but not the selected value.
Take a closer look at the manual and find the list of "Form Object Properties". Does it mean that there is a way to determine a specific attribute for a form object? Change the code.
Copy Code code as follows:

var value = $ ("input[name= ' Radio1 '][type= ' Radio ']:checked"). Val ();

In IE, FireFox, Chrome, Safari (3.2) under the test are passed.
By the way, I tested the select element, and the manual was written in a common style, and I could get the correct values in the above browsers.
Copy Code code as follows:

var value1 = $ ("select"). Val (); var value2 = $ ("Select Option:selected"). Val ();

I tested it in the jquery version 1.32 and you can try it.

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.