Home  >  Article  >  Web Front-end  >  Detailed explanation of the steps to obtain the radio value with jQuery

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

php中世界最好的语言
php中世界最好的语言Original
2018-04-23 17:25:101745browse

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:

9960d1be23362d53022a0c1cbd040b24
  5c1f7e325cea0b29c267e237c774a5a6男
  a846316c40ad5e775c1706519cc56949女
94b3e26ee717c64999d7867364b1b4a3

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的值

If you want to get the value of a certain radio There are several methods for the value. The code is given directly:

1,

$('input[name="testradio"]:checked').val();
$('input:radio:checked').val();
$('input[@name="testradio"][checked]');
$('input[name="testradio"]').filter(':checked');

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

$('input[name="testradio"]').each(function(){2.alert(this.value);3.});

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

$('input[name="testradio"]:eq(1)').val()

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!

Statement:
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