如何在jQuery中获取单选按钮组的值
How to get value of radio button group in jQuery?
我找不到合适的答案。
var inputs = $("root :input[typeof]");
// looping thru elements
inputs.each(function(index) {
var name = $(this).attr('name'); // get element by name (or by id)
var value = $(this).val(); // get element value
// How do I capture radio button (or checkbox) group
// element in this loop? And how do I get a checked value of such group?
// Note, in here $(this) should be the radio button group element
}
所以,问题就在代码注释中。在那个循环中如何获得单选按钮组元素的值?
在HTML中,如果您按名称引用这样的组,您将自动获得该组中选中单选按钮的值。
当$(this)是循环中的当前元素时,在jQuery中如何做到这一点?
感谢
//注意,在这里$(this)应该是单选按钮组元素
如果是这样的话,那么这将找到被检查的单选按钮的值:
$(this).find('input:checked').val();
这里有一个检查无线电输入的函数:
function CheckRadioList() {
$('input:radio').each(function () {
// your code here, you can storage them or do what you want.
console.log($(this).prop('checked'));
});
}
如果你想测试它,这里有一个演示:http://jsfiddle.net/jpmbL49r/
- 名称:
$(this).attr('name');
- id:
$(this).attr('id');
- 已检查:
$(this).prop('checked')
我希望它能有所帮助!
相关文章:
- Javascript:无法获取变量中的单选按钮值
- 通过ajax到php文件获取单选按钮值
- 如何获取单选按钮的多个实例的选定单选按钮值
- (extjs)获取表单中单选按钮的选定值.不返回该值
- 如何从单选按钮中获取多个值,然后将它们分配到单个变量中并在页面上显示
- 如何在jQuery中获取单选按钮组的值
- 如何在不使用jQuery的情况下设置数组以获取单选按钮值
- 获取Javascript中单选按钮的true或false
- 如何使用jquery在网格视图中获取所选单选按钮的值
- 从选中的单选按钮获取文本节点
- 如何从人工任务表单中的单选按钮获取检查值
- 从单选按钮获取数据
- 使用带有javascript的单选按钮..获取null错误
- 从多个复选框和单选按钮获取信息
- Javascript从单选按钮获取信息
- 使用jquery从单选按钮获取span价格
- 从输入单选按钮获取平均值
- 谷歌表单脚本-从单选按钮获取值,目前未定义
- 从mdl单选按钮获取值
- 如何从选定的单选按钮获取值