当我单击我的事件侦听器使其转到下一个问题时,我希望复选框有点"刷新"。 现在它卡在了玩家在上一个任务中的回答,请给我 som 帮助
<span id="choices" class="hidden">
<input type="checkbox" id="choice1" class="checkboxes"> <span id="answer1"></span>
<br>
<br>
<input type="checkbox" id="choice2" class="checkboxes"> <span id="answer2"></span>
<br>
<br>
<input type="checkbox" id="choice3" class="checkboxes"> <span id="answer3"></span>
<br>
<br>
<input type="checkbox" id="choice4" class="checkboxes"> <span id="answer4"></span>
<br>
<br>
<hr style="margin-bottom: 50px">
<button id="next"> Next</button>
</span>
事件列表者
next.addEventListener("click", function (e) {
if (quiz.checkAnswer()) {
quiz.score++;
};
console.log(quiz.checkAnswer());
quiz.nextQuestion();
quiz.display();
if(quiz.currentQuestion < quiz.quests.length) {
document.getElementById("question").innerHTML = quiz.quests[quiz.currentQuestion].question;
document.getElementById("answer1").innerHTML = quiz.quests[quiz.currentQuestion].answer[0].alt;
document.getElementById("answer2").innerHTML = quiz.quests[quiz.currentQuestion].answer[1].alt;
document.getElementById("answer3").innerHTML = quiz.quests[quiz.currentQuestion].answer[2].alt;
document.getElementById("answer4").innerHTML = quiz.quests[quiz.currentQuestion].answer[3].alt;
}
quiz.setName();
quiz.setnoOfQuestions();
quiz.progress();
quiz.amountOfQuestions();
quiz.finalScore();
});
一种可能的方法是
const kases = document.querySelectorAll('#choice1, #choice2, #choice3, #choice4')
// ...
next.addEventListener("click", function (e) {
//...
kases.forEach( k=>k.checked = false )
//...
}