⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 14-23.htm

📁 JavaScript学习的网页教程。内容简单易懂
💻 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 + -