jquery - 获取已检查 radio 的值

标签 jquery radiobuttonlist

我正在尝试获取检查 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();
 });

有什么好的建议可以解决这个问题吗?

最佳答案

您的代码是正确的,您必须将值放在某个位置:

jsfiddle demo

$(document).on('click', '#test', function(){
    alert($('input:radio[name=txtCorrectAnswer]:checked').val());
 });

可以了解设置值here.

关于jquery - 获取已检查 radio 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19336452/

相关文章:

jquery - 需要有关此脚本的帮助

Jquery 删除类、添加类

javascript - RadioButtonList 在 javascript 中选择的值

c# - 单选按钮列表未正确选择新值

asp.net - 将单选按钮列表绑定(bind)到 gridview 中的列

javascript - 加载页面 Ajax,然后将其滑入页面或插件

javascript - Flash 运行时在使用 PLupload 的 IE8 中不起作用

.net - 所有单选按钮组是否被点击

android - 将复选框添加到单选集 AlertDialog

javascript - 在更改时使用 javascript 清除选择选项