gpt4 book ai didi

JavaScript 警报框弹出问题

转载 作者:行者123 更新时间:2023-12-02 15:29:27 25 4
gpt4 key购买 nike

我遇到了单击提交按钮后警报框未出现在屏幕上的问题。我已经在这个论坛和网上搜索了答案,但我没有看到我的代码有什么问题。与我的大多数问题一样,解决方案可能是一个简单的修复,但在检查我的代码后我似乎找不到问题。如有任何帮助,我们将不胜感激。

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

<input id="stop" type="button" value="Submit Answers" onclick="stopClock()"/>

最佳答案

可能您有一个 undefined variable ,请检查此工作演示

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

关于JavaScript 警报框弹出问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33444149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com