Home > Web Front-end > JS Tutorial > body text

How to get the value of Radio element in jQuery_jquery

WBOY
Release: 2016-05-16 17:30:32
Original
889 people have browsed it

I also found that the JavaScript code I wrote ran incorrectly under FireFox. The reason was very frustrating. When getting the value of a Radio element, I only got undefind.
Googled it, and most of them are the same as the method I used

Copy the code The code is as follows:

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

This sentence is in IE and Safari The test passes under (3.2), but the selected value cannot be obtained under FireFox and Chrome.
Read the manual carefully and find the list of "Form Object Properties". Could it be said that there is a special attribute judgment method for form objects? Change the code
Copy the code The code is as follows:

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

The test passed under IE, FireFox, Chrome, and Safari (3.2).
By the way, I tested the select element. The way it is written in the manual is the way I usually write it. The correct value can be obtained in the above browsers.
Copy code The code is as follows:

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

I tested it under jQuery 1.32 version, you can try it.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template