How to get the selected value of the radio button list in jquery?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-17 16:11:57

问题


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


回答1:


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();



回答2:


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

$("#btn").click(function() {
   $('input[type="radio"]:checked').val();
});


来源:https://stackoverflow.com/questions/743052/how-to-get-the-selected-value-of-the-radio-button-list-in-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!