所以我昨晚有这个工作,这是一个10个问题的测验。我今天做了一些修改,现在当我点击检查答案时,如果答案是否正确,我已经失去了在jumbotron中显示的功能。继续下一个问题仍然删除并重新填充列表。只是检查问题答案的按钮被打破了。这是jsFiddle链接:
答案 0 :(得分:1)
问题与您的i
值在侦听器回调块中无效有关。您可以使用currentQuestion
值来解决此问题,例如:
$('#submit').on('click', function() {
var answer = $('input[name="1"]:checked').val();
if (answer == questionsArray[currentQuestion]['answer']) {
correctAnswers++;
$('.jumbotron').html(answer + "?<br><br> That's correct! You have " + correctAnswers + " out of 10 correct!");
} else {
$('.jumbotron').html(answer + "? <br><br> Oh dear, that's so so wrong! You have " + correctAnswers + " out of 10 correct");
}
return false;
});