我找不到适合我的案例的正确答案。
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 中执行此操作?
谢谢
最佳答案
// Note, in here $(this) should be the radiobutton-group element
如果是这种情况,那么这将找到选中的单选按钮的值:
$(this).find('input:checked').val();
关于javascript - 如何在 jQuery 中获取单选按钮组的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29304807/