我有这个测验应用程序,当我第一次运行它时它会显示结果,但是当我再次单击“播放”并再次运行该应用程序时,它没有显示结果。我知道我在以下代码中遇到问题,但无法弄清楚。请帮助 -
//This function is for reseting the quiz
var resetQuiz = function() {
if (resetCounter++ > 1 || quizOver || confirm('Are you sure you want to reset the quiz?')) {
counter = 0;
quizOver = false;
results = {count: 0, answers: [], currentScore: 0};
scoreNode.addClass('no_score').text('');
questionBlock.show();
nextQuestion();
}
};
//This function handle the results
var showResults = function() {
answersBlock.empty();
questionBlock.hide();
showResult.text('You answered ' + results.currentScore + '% of '
+ 'the questions correctly.');
quizOver = true;
actionButton.text('Play again');
};
完整的应用程序在这里 - http://jsfiddle.net/varunksaini/J5qVd/
最佳答案
在你的 var buttonAction = function() {
你正在做 showResult.hide();
在你点击“Play Again”后它设置为 显示:无
但是,您永远不会在 showResults() 函数中调用 showResult.show();
。所以它仍然是 display:none
。您只需在更改文本后调用 showResults.show();
。
var showResults = function() {
answersBlock.empty();
questionBlock.hide();
showResult.text('You answered ' + results.currentScore + '% of '
+ 'the questions correctly.');
quizOver = true;
showResult.show(); //Show the results if they have been hidden
actionButton.text('Play again');
};
关于javascript - 当我第二次运行我的应用程序时没有显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19412706/