我正在开发一个基于Web的系统,其中用户可以提供管理员提交的测试,问题是我想实现一个计时器,可以在测验开始时启动并在测试结束时自动提交测试,需要帮助如何我实现了阅读很多aanswers,但没有帮助具体到我的项目。“
<span id="countdown" class="timer"></span>
<script>
var seconds = 40;
function secondPassed() {
var minutes = Math.round((seconds - 30)/60);
var remainingSeconds = seconds % 60;
if (remainingSeconds < 10) {
remainingSeconds = "0" + remainingSeconds;
}
document.getElementById('countdown').innerHTML = minutes + ":" + remainingSeconds;
if (seconds == 0) {
clearInterval(countdownTimer);
document.getElementById('countdown').innerHTML = "Buzz Buzz";
} else {
seconds--;
}
}
var countdownTimer = setInterval('secondPassed()', 1000);
</script>
`