我有一个单选按钮列表,其中id作为值,我想在jquery函数中访问所选的id。
<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();
在按钮点击时,它将获取单选按钮的选定值。
例如,对于列表:
$("#btn").click(function() {
$('input[type="radio"]:checked').val();
});
checked
可以使用,但是selected
不行(至少在 Firefox 13 和 jQuery 1.8 中)。 - supervacuo