Using jquery to get the value of Radio , the most important thing is to master the use of jquery selectors, in a form we usually want to get the value of the selected radio item, so add checked to filter, for example, there are some of the following radio items:
1.
<
input
type
=
"radio"
name
=
"testradio"
value
=
"jquery获取radio的值"
/>jquery获取radio的值<
br
/>
2.
<
input
type
=
"radio"
name
=
"testradio"
value
=
"jquery获取checkbox的值"
/>jquery获取checkbox的值<
br
/>
3.
<
input
type
=
"radio"
name
=
"testradio"
value
=
"jquery获取select的值"
/>jquery获取select的值<
br
/>
To get the value of a radio, there are several ways to give the code directly:
1.$(
‘input[name="testradio"]:checked‘
).val();
2.$(
‘input:radio:checked‘
).val();
3.$(
‘input[@name="testradio"][checked]‘
);
4.
1.
$(
‘input[name="testradio"]‘
).filter(
‘:checked‘
);
Pretty much, if we're going to go through all the radio name Testradio, here's the code.
1.
$(
‘input[name="testradio"]‘
).each(
function
(){
2.
alert(
this
.value);
3.
});
If you want to take the value of a specific radio, such as the value of a second radio, write
1.
$(
‘input[name="testradio"]:eq(1)‘
).val()
To deepen your impressions, run the following instance by modifying
"Text/javascript"src="Https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script><Script Type="Text/javascript">$ (function () {$ ('#go'). Click (function () {varRadio = $ ('input[name= "Testradio"]'). Filter (': Checked'); if(radio.length) alert (Radio.val ()); ElseAlert ('Please select a radio'); }); $('#go2'). Click (function () {$ ('input[name= "Testradio"]'). each (function () {alert ( This. Value); }); }) $('#go3'). Click (function () {alert ($ ('input[name= "Testradio"]:eq (1)'). Val ()); })})</script>"Radio"Name="Testradio"Value="jquery Gets the value of radio"/>jquery gets the value of radio <br/> <input type="Radio"Name="Testradio"value="jquery Gets the value of the checkbox"/>jquery gets the value of the checkbox <br/> <input type="Radio"Name="Testradio"Value="jquery Gets the value of select"/>jquery gets the value of select <br/><button id="Go"> The value of the radio selected </button><button id="Go2"> traverse the values of all radio </button><button id="Go3"> Take the value of a second radio </button></body>Use jquery to get the value of radio