• js实现倒计时


    1. <html>  
    2.     <head>  
    3.         <title>倒计时</title>  
    4.         <!--以下为css样式-->  
    5.         <style type= "text/css">  
    6.             .daojishi h2  
    7.             {   
    8.                 font-family:Helvetica, Microsoft YaHei, Arial, sans-serif;   
    9.                 font-size:14px;  
    10.                 margin-bottom:5px;   
    11.                 color:#151515;  
    12.             }  
    13.             .daojishi #timer  
    14.             {  
    15.                 font-family:Helvetica, Microsoft YaHei, Arial, sans-serif;   
    16.                 font-size:14px;  
    17.                 color:#151515;  
    18.                 font-weight:bold;  
    19.             }  
    20.         </style>  
    21.         <script type = "text/javascript" src = "timer.js">  
    22.         </script>  
    23.     </head>  
    24.     <body onload = "timer()">  
    25.         <div class = "daojishi">  
    26.             <h2>剩余时间为:</h2>  
    27.             <div id = "timer">  
    28.             </div>  
    29.         </div>  
    30.     </body>  
    31. </html>  
    1. function timer()  
    2.             {  
    3.                 var ts = (new Date(2018, 11, 11, 9, 0, 0)) - (new Date());//计算剩余的毫秒数  月份是减一个月的
    4.                 var dd = parseInt(ts / 1000 / 60 / 60 / 24, 10);//计算剩余的天数  
    5.                 var hh = parseInt(ts / 1000 / 60 / 60 % 24, 10);//计算剩余的小时数  
    6.                 var mm = parseInt(ts / 1000 / 60 % 60, 10);//计算剩余的分钟数  
    7.                 var ss = parseInt(ts / 1000 % 60, 10);//计算剩余的秒数  
    8.                 dd = checkTime(dd);  
    9.                 hh = checkTime(hh);  
    10.                 mm = checkTime(mm);  
    11.                 ss = checkTime(ss);  
    12.                 document.getElementById("timer").innerHTML = dd + "天" + hh + "时" + mm + "分" + ss + "秒";  
    13.                 setInterval("timer()",1000);  
    14.             }  
    15.             function checkTime(i)    
    16.             {    
    17.                if (i < 10) {    
    18.                    i = "0" + i;    
    19.                 }    
    20.                return i;    
    21.             }    
  • 相关阅读:
    [最短路,floyd] Codeforces 1202B You Are Given a Decimal String...
    ICPC 2015 Changchun A Too Rich(贪心)
    2016 杭州区域赛补题
    牛客网暑期ACM多校训练营(第六场) A Singing Contest
    牛客网暑期ACM多校训练营(第六场)J Heritage of skywalkert
    牛客网暑期ACM多校训练营(第六场)I Team Rocket (线段树)
    It’s Time for a Montage
    Attack on Alpha-Zet
    ecna 2017 J Workout for a Dumbbell (模拟)
    牛客网暑期ACM多校训练营(第二场)K carpet
  • 原文地址:https://www.cnblogs.com/xurui01/p/3991108.html
Copyright © 2020-2023  润新知