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>
Get a set of radio buttons Object: var obj_payPlat<a href="http://www.php.cn/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,
$('input[name="testradio"]:checked').val(); $('input:radio:checked').val(); $('input[@name="testradio"][checked]'); $('input[name="testradio"]').filter(':checked');
It’s almost complete. If we want to traverse all radios named testradio, the code is as follows
$('input[name="testradio"]').each(function(){2.alert(this.value);3.});
If we 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()
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!