How to get the selected value of the radio button

2019-01-14 15:18发布

I have radio button list which has id as the value, I want to access the selected id in the jquery function.

2条回答
Viruses.
2楼-- · 2019-01-14 15:48

It will get the selected value of the radiobutton at button click.
ex for list

$("#btn").click(function() {
   $('input[type="radio"]:checked').val();
});
查看更多
够拽才男人
3楼-- · 2019-01-14 15:52

If you have HTML that looks like this:

<input type='radio' name='choices' value='1'>
<input type='radio' name='choices' value='2'>
<input type='radio' name='choices' value='3'>
<input type='radio' name='choices' value='4'>
<input type='radio' name='choices' value='5'>

You would get the selected radio value with this:

$("input:radio[name='choices']:checked").val();
查看更多
登录 后发表回答