如何获取jquery中单选按钮列表的选定值?

问题描述:

我有单选按钮列表,其中id为值,我想访问jquery函数中选定的id。如何获取jquery中单选按钮列表的选定值?

如果你有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'> 

你会与此获得所选择的无线电值:

$("input:radio[name='choices']:checked").val(); 
+16

$( “输入:无线​​电[名= '选择']:检查”)VAL();可能会更好地工作。 – 2010-01-29 18:00:02

+1

同意`checked`工作,``selected`不(至少在Firefox 13中,jQuery 1.8) – supervacuo 2012-07-09 20:53:20

它将得到单选按钮的按键点击所选值。 。
EX为列表

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