使用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
11<BODY>
12 <div id="TimeCounter" style="border:1px solid black;margin:1px;padding:2px;width:170px"></div>
13<SCRIPT language=javascript>
14<!--
15function 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}

48show_date_time();
49//-->
50</SCRIPT></div>
51</BODY>
52</HTML>
53
54
posted on 2006-10-31 12:23  空空儿  阅读(1265)  评论(0编辑  收藏  举报