练习 JS做的北京奥运会倒计时,精确到秒(0 位领导批示)

Demo http://www.zdyi.com/code/bj2008/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>北京2008奥运会开幕倒计时</title>
<style>
* {margin:0;padding:0;font-size:12px;font-family:Calibri, Arial, Helvetica, sans-serif;}
body,html {height:100%;}
#beijing2008 {text-align:center;height:100%;line-height:50;color:#333;margin:auto;}
</style>
</head>
<body>
<div id="beijing2008"></div>
<script>
var now = new Date();
function beijing2008()
{
	var iStart = new Date("8/08/2008 20:00:00");//设置奥运会开幕时间
	now.setTime(now.getTime() + 250);//修正误差
 
	days	= (iStart - now) / 1000 / 60 / 60 / 24;
	dayNum 	= Math.floor(days);//获取天数
	hours 	= (iStart - now) / 1000 / 60 / 60 - (24 * dayNum);
	houNum 	= Math.floor(hours);//获取小时
	if(houNum < 10){houNum = "0" + houNum}
	minutes = (iStart - now) / 1000 / 60 - (24 * 60 * dayNum) - (60 * houNum);
	minNum	= Math.floor(minutes);//获取分钟
	if(minNum < 10){minNum = "0" + minNum};
	seconds	= (iStart - now) / 1000 - (24 * 60 * 60 * dayNum) - (60 * 60 * houNum) - (60 * minNum);
	secNum	= Math.floor(seconds);//获取秒钟
	if(secNum < 10){secNum = "0" + secNum};
 
	var show = document.getElementById("beijing2008");
	show.innerHTML = "距2008北京奥运会开幕还有&nbsp;" + dayNum + "&nbsp;天&nbsp;" + houNum + "&nbsp;时&nbsp;" + minNum + "&nbsp;分&nbsp;" + secNum + "&nbsp;秒" 
}
setInterval("beijing2008()",250);
</script>
</body>
</html>

相关文章

分享到新浪微博 推荐到豆瓣 分享到 Google Reader 加入Google书签 嘀咕一下 分享到饭否 分享到做啥 分享到叽歪 分享到鲜果 加入QQ书签 加入百度搜藏 加入雅虎书签 分享到垦一垦

银子曰:还没有领导题词?

请领导指示

验证码 (必须)

Additional comments powered by BackType

随机显示的10篇日志

评论最多的10篇日志

浏览最多的10篇日志