📄 14-23.htm
字号:
<HTML>
<HEAD>
<TITLE>倒计时计数器</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
var running = false
var endTime = null
var timerID = null //在函数外面定义的这3个变量是全局变量,可以在所有的函数中使用
function startTimer() {
running = true
now = new Date()
now = now.getTime()
endTime = now + (1000*20) // change last multiple for the number of Seconds
showCountDown()
}
function showCountDown() {
var now = new Date()
now = now.getTime()
if (endTime - now <= 0) {
stopTimer()
alert("按下“20秒倒计时开始”按钮后,已经过了20秒没有单击“清除计时设置”按钮")
} else {
var delta = new Date(endTime - now)
var theMin = delta.getMinutes()
var theSec = delta.getSeconds() //结束时间与开始时间相差的秒数
var theTime = theMin
theTime += ((theSec < 10) ? ":0" : ":") + theSec
document.forms[0].timerDisplay.value = theTime
//亦可用:document.biaodan.timerDisplay.value = theTime
if (running) {
setTimeout("showCountDown()",1000)
}
}
}
function stopTimer() {
clearTimeout(timerID)
running = false
document.forms[0].timerDisplay.value = "0:00"
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<FORM name="biaodan">
<INPUT TYPE="button" NAME="startTime" VALUE="20秒倒计时开始" onClick="startTimer()">
<INPUT TYPE="button" NAME="clearTime" VALUE="清除计时设置" onClick="stopTimer()"><P>
<INPUT TYPE="text" NAME="timerDisplay" VALUE="" size="26">
</FORM>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -