jQuery 如何在jquery中获取单选按钮列表的选定值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/743052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get the selected value of the radio button list in jquery?
提问by Ravi
I have radio button list which has id as the value, I want to access the selected id in the jquery function.
我有一个以 id 为值的单选按钮列表,我想在 jquery 函数中访问选定的 id。
回答by Paolo Bergantino
If you have HTML that looks like this:
如果您的 HTML 如下所示:
<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();
回答by Ashish Babu
It will get the selected value of the radiobutton at button click.
ex for list
它将在按钮单击时获取单选按钮的选定值。
清单前列
$("#btn").click(function() {
$('input[type="radio"]:checked').val();
});