有没有办法检查jQuery中是否选择了第n个单选按钮?我正在寻找循环一组单选按钮并在另一个区域中使用第n个值。我宁愿不必使用:第一:第二等。
由于
答案 0 :(得分:1)
是这样的:
$("#myRadio").is(":checked")
收集:
$("#myRadioGroup input:radio").each(function(index, element) {
console.log(element.checked);
});
答案 1 :(得分:0)
我希望循环使用一组单选按钮并在另一个区域中使用第n个值
如果你真的想要循环,那么:
$("selector-for-the-radio-buttons").each(function() {
// Use `this.checked` here
});
如果你只想要nth
一个:
$("selector-for-the-radio-buttons")[n].checked
或
$("selector-for-the-radio-buttons:eq(" + n + ")")[0].checked
// or if it may not exist, this will give you undefined instead of an error:
$("selector-for-the-radio-buttons:eq(" + n + ")").prop("checked")
// as will this:
$("selector-for-the-radio-buttons:eq(" + n + ").is(":checked")
答案 2 :(得分:0)
无需循环:
const index = 5
$(':radio:nth(' + index + ')').is(':checked')
答案 3 :(得分:0)
如果您想使用实际的第n种样式,可以使用nth-of-type
方法,就像这样
$('input[type="radio"]:nth-of-type(<whatever-n>)').is(':checked')