这是 HTML
<div class="radios">
<label class="step_radio">
<input class="step_1" type="radio" name="step_1" />
</label>
<label class="step_radio">
<input class="step_1" type="radio" name="step_1" />
</label>
<label class="step_radio">
<input class="step_1" type="radio" name="step_1" />
</label>
</div>
<button type="submit" class="submitQuiz">Отправить</button>
这是JS
$(".submitQuiz").on("click", function (event) {
event.preventDefault();
$('.step_1').each(function() {
if($(this).prop("checked") == true) {
step1 = $(this).index(this);
console.log(step1);
}
});
});
当您单击“提交测验”时,您需要显示所选单选按钮的索引。但它总是只输出0。如何确定索引?
1 个回答