---
title: "实现html页面的倒计时"
author: "linger_yan"
date: "2012-01-30T11:35:10Z"
tags: []
categories: ["Web前端"]
slug: "html"
draft: false
lastmod: "2012-02-13T16:37:51Z"
id: 1382048
url: "https://linger-yan.iteye.com/blog/1382048"
---

<span style="color:indigo">主要通过setInterval函数实现，当发生鼠标点击或者移动时，网页重新倒计时。具体实现如下：


<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>html页面倒计时显示</title>
</head>

<script language="JavaScript" type="text/javascript">
	var seq = 20; 
	var second=1000; //间隔时间1秒钟
	
	function scroll() { 
		document.getElementById('word').innerHTML = seq;
		seq--; 
		if (seq <= 0)
		{
			//倒计时结束后进行的操作
			seq = 20; 
		}
	}
	function reCount() {
		seq=20;
	}
</script>

<body 
**onload="setInterval('scroll()',second)" ** 
onmousemove="reCount()" onmouseover="reCount()" onmouseup="reCount()" onmousedown="reCount()" 
style="width:500px;height:400px;"> 

<div id="word"></div>

</body> 

</html>
</span>