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

Detailed explanation of the steps to obtain the radio value with jQuery

php中世界最好的语言
Release: 2018-04-23 17:25:10
Original
1707 people have browsed it

This time I will bring you jQuery a detailed explanation of the steps to obtain the radio value, and what are the precautions for jQuery to obtain the radio value. The following is a practical case, 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

Obtain a set of radio buttonsObject:var obj_payPlatform = $( '#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 the use of 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 the following radio items:

1.<input type="radio" name="testradio" value="jquery获取radio的值" />jquery获取radio的值
2.<input type="radio" name="testradio" value="jquery获取checkbox的值" />jquery获取checkbox的值
3.<input type="radio" name="testradio" value="jquery获取select的值" />jquery获取select的值
Copy after login

If you want to get the value of a certain radio There are several methods for the value. The code is given 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

is almost complete. If we want to traverse all radios with the name testradio, the code As follows

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

If you 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

I believe you have mastered the method after reading the case in this article. Please come for more exciting information. Pay attention to other related articles on php Chinese website!

Recommended reading:

jquery deletes selected rows in table

##asp.net jquery.form makes asynchronous image upload function

The above is the detailed content of Detailed explanation of the steps to obtain the radio value with 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!