昨天的视频python模拟在线测试1。
核心代码:
timer = setInterval(function() {
// 时间到自动提交试卷
if (count==0){
clearInterval(timer)
alert("时间到,已自动交卷")
}
count--;
tag3.innerHTML = showNum(count % 60)
tag2.innerHTML = showNum(parseInt(count / 60) % 60)
tag1.innerHTML = showNum(parseInt(count / 60 / 60))
}, 1000)
静态网页(复制到本地即可运行):
myclock.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="../static/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="../static/fontawesome/css/all.css">
</head>
<body>
<p style="font-size: 48px; color: Dodgerblue;"><i class="far fa-clock"></i> <span id="h">02</span>:<span id="m">00</span>:<span id="s">00</span></p>
<script>
window.onload = function() {
var tag1 = document.getElementById('h')
var tag2 = document.getElementById('m')
var tag3 = document.getElementById('s')
var count = 60*120
var timer = null //timer变量记录定时器setInterval的返回值
timer = setInterval(function() {
// 时间到自动提交试卷
if (count==0){
clearInterval(timer)
alert("时间到,已自动交卷")
}
count--;
tag3.innerHTML = showNum(count % 60)
tag2.innerHTML = showNum(parseInt(count / 60) % 60)
tag1.innerHTML = showNum(parseInt(count / 60 / 60))
}, 1000)
//封装一个处理单位数字的函数
function showNum(num) {
if (num < 10) {
return '0' + num
}
return num
}
}
</script>
</body>
</html>
服务器端就需要加一个到时自动点击提交按钮,相当于人点击按钮一样。
document.getElementsByTagName('form')[0].submit();
python知识库