我是JavaScript和HTML的新手,但我慢慢獲取HTML,但JavaScript正在努力工作。當我點擊開始測驗按鈕時,我遇到了讓我有計數器開始的問題。當我單擊「提交答案」按鈕時,我也遇到了出現警告框的問題。我不想找人給我答案,但一些指導將有所幫助。Javascript幫助 - 定時器(不計數)和警報框(不顯示)
<head>
<meta charset="UTF-8" />
<title>Trivia Quiz: Movies</title>
<script src="modernizr-1.5.js" type="text/javascript" ></script>
<link href="quiz.css" rel="stylesheet" type="text/css" />
<script src="functions.js" type="text/javascript" ></script>
<script type="text/javascript">
var seconds = "0";
var clockID;
</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>
<script type="text/javascript">
function stopClock() {
clearInterval (clockId);
correctAns = gradeQuiz();
window.alert("You have" + correctAns + "correct of 5 in" + timer + "seconds");
}
</script>
</head>
<body onload="resetQuiz()">
<form id="quiz" name="quiz" action="">
<header>
<img src="tlogo.png" alt="Online Trivia" />
<nav class="horizontal">
<ul>
<li><a href="#">Top Scores</a></li>
<li><a href="#">Submit a Quiz</a></li>
<li><a href="#">Quiz Bowl</a></li>
<li><a href="#">Your Account</a></li>
</ul>
</nav>
</header>
<nav class="vertical">
<h1>Categories</h1>
<ul>
<li><a href="#">Arts</a></li>
<li><a href="#">Books</a></li>
<li><a href="#">Culture</a></li>
<li><a href="#">Geography</a></li>
<li><a href="#">History</a></li>
<li><a href="#">Movies</a></li>
<li><a href="#">Music</a></li>
<li><a href="#">People</a></li>
<li><a href="#">Random</a></li>
<li><a href="#">Science</a></li>
<li><a href="#">Sports</a></li>
<li><a href="#">Television</a></li>
</ul>
</nav>
<section id="main">
<h1>Movie Trivia</h1>
<p>
All of our trivia quizzes are scored on the number of correct
answers and the time required to submit those answers.
</p>
<p>
To start the quiz, click the <b>Start Quiz</b> button below,
which will reveal the first page of quiz questions and start
the timer. When you have completed the questions, click
the <b>Submit Answers</b> button on the quiz form.
</p>
<aside>
<input name="quizclock" id="quizclock" value="0" />
<input id="start" type="button" value="Start Quiz" onclick="startClock()" />
<input id="stop" type="button" value="Submit Answers" onclick="stopClock()"/>
</aside>
</section>
</form>
</body>
提供的代碼是部分代碼,我相信這是問題所需的代碼的唯一部分。謝謝。根據要求
復位功能:
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;
}
爲什麼'seconds'一個字符串?無論如何,只要將值設爲'0'即可。此外,這行'document.getElementByID('quizclock')value = seconds;'應該是'document.getElementById('quizclock')。value = seconds;'。請務必檢查您的控制檯是否有任何錯誤。另外,你能否在你的問題中提供你的'resetQuiz'函數? – Dom
我已經添加了resetQuiz()函數。 – Ph1shPhryd