Home > Web Front-end > JS Tutorial > Detailed explanation of how to get the value of the selected radio button using jQuery

Detailed explanation of how to get the value of the selected radio button using jQuery

伊谢尔伦
Release: 2017-06-28 13:11:37
Original
3382 people have browsed it

This article will share with you two pieces of example code to explain to youjqueryGet the value of the selected radio buttonradio, which is very good and has reference value. Let’s take a look

Example 1:

<p id="wrap">
  <input type="radio" name="payMethod" value="1" />男
  <input type="radio" name="payMethod" value="2" />女
</p>
Copy after login

Get a set of radio buttons Object: var obj_payPlat<a href="//m.sbmmt.com/wiki/125.html" target="_blank">for</a>m = $('#wrap input[name="payMethod"]');

Get the value of the selected button: var val_payPlatform = $('#wrap input[name ="payMethod"]:checked ').val();

Example 2:

Use jquery to get the value of radio, the most important thing is to master When using the jquery selector, in a form we usually want to get the value of the selected radio item, so we need to add checked to filter. For example, there are some radio items as follows:

1.jquery gets the value of radio

2.jquery gets the value of checkbox

3.jquery gets The value of select

If you want to get the value of a certain radio, there are several methods as follows, just give the code directly:

1,

$(&#39;input[name="testradio"]:checked&#39;).val();
$(&#39;input:radio:checked&#39;).val();
$(&#39;input[@name="testradio"][checked]&#39;);
$(&#39;input[name="testradio"]&#39;).filter(&#39;:checked&#39;);
Copy after login

It’s almost complete. If we want to traverse all radios named testradio, the code is as follows

$(&#39;input[name="testradio"]&#39;).each(function(){2.alert(this.value);3.});
Copy after login

If we want to get the value of a specific radio, such as the value of the second radio, write like this

$(&#39;input[name="testradio"]:eq(1)&#39;).val()
Copy after login

The above is the detailed content of Detailed explanation of how to get the value of the selected radio button using jQuery. For more information, please follow other related articles on the PHP Chinese website!

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