<button onclick="checkAnswer(1)" style="width: 100%; height: 320px; font-size: 40px;">{if $zushu eq 1 and $tiliang eq 1}看答案{else}下一题{/if}</button>
function playNotificationSound() {
var audio = new Audio('/oa/huidazhengque.mp3'); // 将notification.mp3替换为你的音频文件路径
audio.onended = function() {
alert('正确,答对了!');
};
audio.play();
}
function playNotificationSound1() {
var audio = new Audio('/oa/cuowu.mp3'); // 将notification.mp3替换为你的音频文件路径
audio.onended = function() {
alert('答错了!');
};
audio.play();
}
function checkAnswer(tiaodaan) {
if($.trim($("input[name=answerInput]").val()) == "")
{
$("input[name=answerInput]").focus();
return false;
}
document.getElementById('question1').textContent='';
isQuestionDisplayed = false;//每一题重新禁用按纽
const userAnswer = parseInt(document.getElementById('answerInput').value);
if (userAnswer === questions[currentQuestionIndex].answer) {
var huidashijian=6000;
document.getElementById('question').textContent = questions[currentQuestionIndex].answer;
playNotificationSound();
} else {
var huidashijian=5000;
playNotificationSound1();
document.getElementById('question').textContent = questions[currentQuestionIndex].answer;
}
setTimeout(() => {
document.getElementById('answerInput').value = '';
$("input[name=answerInput]").focus();
let endTime = new Date().getTime(); // 记录结束时间
let totalTime = (endTime - startTime) / 1000; // 转换为秒
//保存所有题目
if(numbers=='')
{
if (userAnswer !== undefined) { // 确保 userAnswer 已被定义
questions[currentQuestionIndex].userAnswer = userAnswer; // 添加这一行
}
if (userAnswer === questions[currentQuestionIndex].answer) {
questions[currentQuestionIndex].isCorrect = true;
} else {
questions[currentQuestionIndex].isCorrect = false;
}
}
else
{
// 更新用户答案和是否正确的状态
questions[currentQuestionIndex].userAnswer = userAnswer;
questions[currentQuestionIndex].isCorrect = userAnswer === questions[currentQuestionIndex].answer;
}
localStorage.setItem('questionsData', JSON.stringify(questions));
if(tiliang==1)
{
if (currentQuestionIndex < jidaoti) {//几道题
currentQuestionIndex++;
document.getElementById('question').textContent = '';
if(tiaodaan==1)
{
generateQuestion(numbers);
}
else
{
window.location.href = "/oa/oa_zxsxl.php?act=jieguo&totalTime="+totalTime+"&type={$type}&type_text={$type_text}&xingshi={$xingshi}&xingshi_text={$xingshi_text}&tiliang={$tiliang}&zushu={$zushu}&bishu={$bishu}&shijian={$shijian}&yusu={$yusu}&timulibiao="+encodeURIComponent(timulibiao)+"";
}
} else {
window.location.href = "/oa/oa_zxsxl.php?act=jieguo&totalTime="+totalTime+"&type={$type}&type_text={$type_text}&xingshi={$xingshi}&xingshi_text={$xingshi_text}&tiliang={$tiliang}&zushu={$zushu}&bishu={$bishu}&shijian={$shijian}&yusu={$yusu}&timulibiao="+encodeURIComponent(timulibiao)+"";
}
}
else
{
if(numbers=='')
{
currentQuestionIndex++;
document.getElementById('question').textContent = '';
generateQuestion(numbers);
}
else
{
window.location.href = "/oa/oa_zxsxl.php?act=jieguo&totalTime="+totalTime+"&type={$type}&type_text={$type_text}&xingshi={$xingshi}&xingshi_text={$xingshi_text}&tiliang={$tiliang}&zushu={$zushu}&bishu={$bishu}&shijian={$shijian}&yusu={$yusu}&timulibiao="+encodeURIComponent(timulibiao)+"";
}
}
if(xingshi==1 || xingshi==2)
{
document.getElementById('question').textContent = '请看题';
}
else
{
document.getElementById('question').textContent = '请听题';
speak1('请听题');
}
}, huidashijian);
}
这里有一个小BUG,就是如果我连续点击“下一题”按纽时,我点几下,音频和弹框就重复几次,怎么弄才能不管点几下,音频和弹框只出现一次?