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>
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!