[英]JavaScript Alert Box Popup Issue
I am having an issue with an Alert Box not appearing on the screen after I click a submit button. 单击提交按钮后,屏幕上没有出现警报框,我遇到了问题。 I have searched this forum and online for answers and I don't see what is wrong with my code. 我已经在这个论坛和在线上搜索了答案,但是我看不出我的代码有什么问题。 As with most of my issues, the solution is probably a simple fix but I can't seem to find the issue after going through my code. 与我的大多数问题一样,该解决方案可能是一个简单的修复程序,但在遍历代码后似乎找不到该问题。 Any help is appreciated. 任何帮助表示赞赏。
javascript code JavaScript代码
<script type="text/javascript">
function stopClock() {
clearInterval (clockId);
correctAns = gradeQuiz();
alert('You have' + correctAns + 'correct of 5 in' + timer + 'seconds');
}
</script>
<script type="text/javascript">
function runClock() {
seconds++;
document.getElementById('quizclock').value=seconds;
}
</script>
<script type="text/javascript">
function startClock() {
showQuiz();
clockId=setInterval ("runClock()", 1000);
}
</script>
function resetQuiz() {
document.quiz.quizclock.value = 0;
for (i=0; i<document.quiz.elements.length; i++)document.quiz.elements[i].disabled=false;
document.quiz.stop.disabled = true;
}
function showQuiz() {
document.getElementById("quiztable").style.visibility="visible";
document.quiz.start.disabled = true;
document.quiz.stop.disabled = false;
}
function hideQuiz() {
document.getElementById("quiztable").style.visibility="hidden";
}
function gradeQuiz() {
correct=0;
if (document.quiz.q1[1].checked) correct++;
if (document.quiz.q2[3].checked) correct++;
if (document.quiz.q3[0].checked) correct++;
if (document.quiz.q4[3].checked) correct++;
if (document.quiz.q5[2].checked) correct++;
document.getElementById("cor1").style.backgroundColor="yellow";
document.getElementById("cor2").style.backgroundColor="yellow";
document.getElementById("cor3").style.backgroundColor="yellow";
document.getElementById("cor4").style.backgroundColor="yellow";
document.getElementById("cor5").style.backgroundColor="yellow";
for (i=0; i<document.quiz.elements.length; i++)document.quiz.elements[i].disabled=true;
return correct;
}
html for button that pops up the alert 用于弹出警报的按钮的html
<input id="stop" type="button" value="Submit Answers" onclick="stopClock()"/>
Probably you have a variable undefined, check this working demo 可能您有一个未定义的变量,请查看此工作示例
function gradeQuiz() {
return 'something';
}
var clockId, i = timer = 0;
clockId = setInterval(function() {
i++;
$('h2').text(i);
}, 200);
function stopClock() {
clearInterval (clockId);
correctAns = gradeQuiz();
alert('You have ' + correctAns + ' correct of 5 in ' + timer + ' seconds');
}
$('button').on('click', stopClock);
http://jsbin.com/toyibekivu/edit?html,js,output http://jsbin.com/toyibekivu/edit?html,js,输出
If you remove 如果删除
alert('You have' + correctAns + 'correct of 5 in' + timer + 'seconds');
from your stopClock()
function no alert will appear on the screen. 通过stopClock()
函数,屏幕上不会显示任何警报。
You need to define your variables and use seconds
in alert
. 您需要定义变量,并在alert
使用seconds
。
Change your functions to: 将功能更改为:
var clockId;
var seconds = 0;
function stopClock() {
clearInterval (clockId);
correctAns = gradeQuiz();
alert('You have' + correctAns + 'correct of 5 in' + seconds + 'seconds');
}
function startClock() {
showQuiz();
seconds = 0;
clockId=setInterval (runClock, 1000);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.