<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 2 <html>
 3 <head>
 4     <title>团购、定时抢购倒计时 </title>
 5     <meta http-equiv="content-type" content="text/html; charset=gb2312" />
 6     <meta name="keywords" content="" />
 7     <meta name="description" content="" />
 8 
 9     <script language="JavaScript">
10 
11         var tms = [];
12         var day = [];
13         var hour = [];
14         var minute = [];
15         var second = [];
16         function takeCount() {
17             setTimeout("takeCount()", 1000);
18             for (var i = 0, j = tms.length; i < j; i++) {
20                 tms[i] -= 1000;
21                 //计算天、时、分、秒、
22                 var days = Math.floor(tms[i] / (1000 * 60 * 60 * 24));
23                 var hours = Math.floor(tms[i] / (1000 * 60 * 60)) % 24;
24                 var minutes = Math.floor(tms[i] / (1000 * 60)) % 60;
25                 var seconds = Math.floor(tms[i] / 1000) % 60;
26                 if (days < 0)
27                     days = 0;
28                 if (hours < 0)
29                     hours = 0;
30                 if (minutes < 0)
31                     minutes = 0;
32                 if (seconds < 0)
33                     seconds = 0;
34                 //将天、时、分、秒插入到html中
35                 document.getElementById(day[i]).innerHTML = days;
36                 document.getElementById(hour[i]).innerHTML = hours;
37                 document.getElementById(minute[i]).innerHTML = minutes;
38                 document.getElementById(second[i]).innerHTML = seconds;
39             }
40         }
41         setTimeout("takeCount()", 1000);
42     </script>
43 
44 </head>
45 <body>
46     <div>
47         <ul>
48             <li style="width: 300px;">剩余时间: <span id="d1" style="font-weight: bold">0</span> <span>
49                 天 </span><span id="h1" style="font-weight: bold">0</span> <span>小时 </span><span id="m1"
50                     style="font-weight: bold">0</span> <span>分 </span><span id="s1" style="font-weight: bold">
51                         0</span> <span>秒</span></li>
52 
53             <script type="text/javascript">
54                 tms[tms.length] = "168935343345";
55                 day[day.length] = "d1";
56                 hour[hour.length] = "h1";
57                 minute[minute.length] = "m1";
58                 second[second.length] = "s1";
59             </script>
60 
61             <li style="width: 300px;">剩余时间: <span id="d2" style="font-weight: bold">0</span> <span>
62                 天 </span><span id="h2" style="font-weight: bold">0</span> <span>小时 </span><span id="m2"
63                     style="font-weight: bold">0</span> <span>分 </span><span id="s2" style="font-weight: bold">
64                         0</span> <span>秒</span></li>
65 
66             <script type="text/javascript">
67                 tms[tms.length] = "1689353433455";
68                 day[day.length] = "d2";
69                 hour[hour.length] = "h2";
70                 minute[minute.length] = "m2";
71                 second[second.length] = "s2";
72             </script>
73 
74         </ul>
75     </div>
76 </body>
77 </html>
78 

完整代码点击团购、定时抢购倒计时js版

转:http://www.cnblogs.com/xiaohai511/archive/2010/08/02/1790303.html

04-28 19:27