天天看點

JS-倒計時效果

團購-限時搶

1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>團購——限時搶</title>
 6 <link rel="stylesheet" href="style.css"  />
 7 </head>
 8 
 9 <body>
10 <div class="content3">
11 <div class="time">還剩 <span id="LeftTime"></span></div>
12 </div>
13 <script>
14 function FreshTime()
15 {
16         var endtime=new Date("2017/5/15,12:20:12");//結束時間
17         var nowtime = new Date();//目前時間
18         var lefttime=parseInt((endtime.getTime()-nowtime.getTime())/1000); 
19         d=parseInt(lefttime/3600/24);
20         h=parseInt((lefttime/3600)%24);
21         m=parseInt((lefttime/60)%60);
22         s=parseInt(lefttime%60);
23        
24         document.getElementById("LeftTime").innerHTML=d+"天"+h+"小時"+m+"分"+s+"秒";
25         if(lefttime<=0){
26         document.getElementById("LeftTime").innerHTML="團購已結束";
27         clearInterval(sh);
28         }
29 }
30 FreshTime()
31 var sh;
32 sh=setInterval(FreshTime,1000);
33 </script>
34 </body>
35 </html>