【发布时间】:2016-01-23 06:10:16
【问题描述】:
我在我正在制作的问答游戏中使用了 javascript 警报的替代方法。回答一个问题后,应该显示一个“警报”(我在这里调用swal,自定义警报),并且应该在转到#2 问题之后执行nextQuestion。
启用自定义警报后,验证仍然可以正常工作,并且警报/模式显示正常。但是,它会移动到下一个问题在用户点击它之前,这与警报的工作方式不同。这是一个问题,因为警报隐藏了下一个问题(并且计时器再次开始运行)。
验证后我已移动that.nextQuestion();,但没有运气。 swal 警报出现后,测验仍会移动到 nextQuestion。
如何修复此序列以在清除警报之后而不是之前执行 nextQuestion?
Quiz.prototype.checkAnswer = function(e) {
var selectedIndex = $(e.target).data('index');
var that = this;
$.getJSON('/api/validate_answer/' + this.participationId + '/' + this.quizCurrent, { answer: selectedIndex }, function(data) {
if (data.result) {
swal({ title: "Good job!", text: "You were right!", type: "success", confirmButtonText: "Next" });
that.score += 1;
}
else {
swal({ title: "Wrong!", text: "That wasn't correct...", type: "error", confirmButtonText: "Next" });
}
that.nextQuestion();
});
}
Quiz.prototype.timer = function() {
var that = this;
this.timing--;
$('div.timer strong').text(this.timing);
if (this.timing <= 0) {
$.getJSON('/api/skip_question/' + this.participationId, function() {
that.nextQuestion();
})
}
}
【问题讨论】:
-
请显示
swal函数
标签: javascript jquery