我正在尝试获取检查 radio 的具有特定名称的 radio 组的值。
但它没有给我值(value)。
这是一个 fiddle :http://jsfiddle.net/qmHm7/
HTML:
<input type="radio" name="txtCorrectAnswer" value="1">
<input type="radio" name="txtCorrectAnswer" value="2">
<input type="radio" name="txtCorrectAnswer" value="3">
<button id="test">Test</button>
Jquery:
$(document).on('click', '#test', function () {
$('input:radio[name=txtCorrectAnswer]:checked').val();
});
有什么好的建议可以解决这个问题吗?
最佳答案
您的代码是正确的,您必须将值放在某个位置:
$(document).on('click', '#test', function(){
alert($('input:radio[name=txtCorrectAnswer]:checked').val());
});
可以了解设置值here.
关于jquery - 获取已检查 radio 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19336452/