首页 > 代码库 > 倒计时

倒计时

技术分享

 1 <!DOCTYPE html>
 2 <html>
 3 <head lang="en">
 4     <meta charset="UTF-8">
 5     <title></title>
 6     <style>
 7         body {
 8             font-size: 40px;
 9             text-align: center;
10             color: pink;
11         }
12     </style>
13     <script>
14         window.onload = function () {
15             function $(id){
16                 return document.getElementById(id);
17             }
18             function $arr(array){
19                 return document.getElementsByTagName(array);
20             }
21 
22             var endTime = new Date("2017/07/11 10:00:00");
23             setInterval(clock,1000);
24             function clock(){
25                 var nowTime = new Date();
26                 var s = parseInt((endTime.getTime()-nowTime.getTime())/1000);
27                 var day = parseInt(s/3600/24);
28                 var hour = parseInt(s/3600%24);
29                 var minute = parseInt(s/60%60);
30                 var second = parseInt(s%60);
31                 day<10 ? day="0"+day : day;
32                 hour<10 ? hour="0"+hour : hour;
33                 minute<10 ? minute="0"+minute : minute;
34                 second<10 ? second="0"+second : second;
35                 $("box").innerHTML = "距离考试还有 "+day+"天 "+hour+"小时 "+minute+"分 "+second+"秒";
36             }
37 
38 
39         }
40     </script>
41 </head>
42 <body>
43     <div id="box"></div>
44 </body>
45 </html>

 

倒计时