510   JS

直接上代码,肯定是你想要的

 <!DOCTYPE html>
<html>
 <head>
 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
 <title>Home</title>
 </head>
 <body> 
 <div style="text-align:center">
 
 <p>
 timer : <span id = 'timer'></span>
 </p>




 </div>

 <script>
 // 还剩几秒
 var globalTimer = 6*24*60*60;


 if(globalTimer > 0){
 timer();
 }

 function timer(){
 var ds = 24*60*60;
 var hs = 60*60;
 var ms = 60;
 
 var time= globalTimer;
 var day=Math.floor(time/ds);
 var hour=Math.floor(time%ds/hs);
 var minute=Math.floor(time%hs/ms);
 var second=Math.floor(time%ms); 
 
 if(day<=9){
 day="0"+day;
 }
 if(hour<=9){
 hour="0"+hour;
 }
 if(minute<=9){
 minute="0"+minute;
 }
 if(second<=9){
 second="0"+second;
 }

 if(day == '00' && hour == '00' && minute == '00' && second == '00'){
 var date = "倒计时结束";
 }else{
 var date = "还剩 "+day+" 天 "+hour+" 时 "+minute+" 分 "+second+" 秒";
 globalCount--;
 setTimeout("timer()",1000);
 }
 
 document.getElementById("timer").innerHTML = date;

 }




 
 </script>
 </body>
</html>



Leave a Reply

Your email address will not be published. Required fields are marked *