使用JS实现倒计时功能(http://www.cnblogs.com/doll-net)
使用JS实现倒计时功能
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2
<HTML>
3
<HEAD>
4
<TITLE>倒计时</TITLE>
5
<META NAME="Generator" CONTENT="EditPlus">
6
<META NAME="Author" CONTENT="">
7
<META NAME="Keywords" CONTENT="">
8
<META NAME="Description" CONTENT="">
9
</HEAD>
10![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
<BODY>
12
<div id="TimeCounter" style="border:1px solid black;margin:1px;padding:2px;width:170px"></div>
13
<SCRIPT language=javascript>
14
<!--
15
function show_date_time(){
16
window.setTimeout("show_date_time()", 1000);
17
target=new Date(2007,9,19,10,13,0);
18
today=new Date();
19
timeold=(target.getTime()-today.getTime());
20
21
sectimeold=timeold/1000
22
secondsold=Math.floor(sectimeold);
23
msPerDay=24*60*60*1000
24
e_daysold=timeold/msPerDay
25
daysold=Math.floor(e_daysold);
26
e_hrsold=(e_daysold-daysold)*24;
27
hrsold=Math.floor(e_hrsold);
28
e_minsold=(e_hrsold-hrsold)*60;
29
minsold=Math.floor((e_hrsold-hrsold)*60);
30
seconds=Math.floor((e_minsold-minsold)*60);
31
32
if (daysold<0) {
33
document.getElementById("TimeCounter").innerHTML="逾期,倒计时已经失效";
34
}
35
else{
36
if (daysold<10) {daysold="0"+daysold}
37
if (daysold<100) {daysold="0"+daysold}
38
if (hrsold<10) {hrsold="0"+hrsold}
39
if (minsold<10) {minsold="0"+minsold}
40
if (seconds<10) {seconds="0"+seconds}
41
if (daysold<3) {
42
document.getElementById("TimeCounter").innerHTML="<font color=red>"+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒</font>";
43
}
44
else
45
document.getElementById("TimeCounter").innerHTML=daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒";
46
}
47
}
48
show_date_time();
49
//-->
50
</SCRIPT></div>
51
</BODY>
52
</HTML>
53![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
54![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
27
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
28
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
29
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
30
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
31
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
32
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
33
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
34
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
35
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
36
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
37
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
38
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
39
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
40
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
41
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
42
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
43
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
44
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
45
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
46
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
47
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
48
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
49
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
50
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
51
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
52
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
53
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
54
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://images.cnblogs.com/cnblogs_com/mephisto/638707/o_%E6%94%AF%E4%BB%98%E5%AE%9D3.png)
![](https://img.alipay.com/sys/personalprod/style/mc/btn-index.png)
博文作者:mephisto
本文版权归作者和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作!
如果阅读了本文章,觉得有帮助,您可以选择捐助我:
![](http://pic.cnitblog.com/face/22672/20140415170007.png)