Radio element value method under jQuery

Source: Internet
Author: User
Tags php website
I also found that the JavaScript code I wrote had an error running in FireFox. The reason was very depressing. When I got the value of a Radio element, I only got undefind. Google, most of the methods I use are the same 1 varvalue $ (& quot; input [name & amp; #39; radio1 & amp; #39;] [ty...

I also found that the JavaScript code I wrote had an error running in FireFox. The reason was very depressing. When I got the value of a Radio element, I only got undefind.

Google, most of them are the same as what I use

1
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

1
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.

1 2
Var value1 = $ ("select"). val (); var value2 = $ ("select option: selected"). val ();
I tested it in jQuery 1.32. You can try it.


From the PHP website of shunzi Network
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.