• js简单时分秒倒计时


    效果:

    javascript:

        <script type="text/javascript">
            function countTime() {
                //获取当前时间
                var date = new Date();
                var now = date.getTime();
                //设置截止时间
                var endDate = new Date("2018-10-25 00:00:00");
                var end = endDate.getTime();
                //时间差
                var differTime = end - now;
                //定义变量,h,m,s保存倒计时的时间
                var h, m, s;
                if (differTime >= 0) {
                    h = Math.floor(differTime / 1000 / 60 / 60);
                    m = Math.floor(differTime / 1000 / 60 % 60);
                    s = Math.floor(differTime / 1000 % 60);
                    h = h < 10 ? ("0" + h) : h;
                    m = m < 10 ? ("0" + m) : m;
                    s = s < 10 ? ("0" + s) : s;
                    document.getElementById("_h").innerHTML = h + "时";
                    document.getElementById("_m").innerHTML = m + "分";
                    document.getElementById("_s").innerHTML = s + "秒";
                    setTimeout(countTime, 1000);
    
                } else {
                    document.getElementById("_h").innerHTML = "00时";
                    document.getElementById("_m").innerHTML = "00分";
                    document.getElementById("_s").innerHTML = "00秒";
                }
    
    
            }
        </script>
    

    HTML: 

    <body onload="countTime()">
        <div class="timer">
            <span id="_h"></span>
            <span id="_m"></span>
            <span id="_s"></span>
        </div>
    </body>
    

      

  • 相关阅读:
    一类分治问题
    [POI2005]DWU-Double-row
    [SCOI2007]降雨量
    [POI2007]ODW-Weights(贪心)
    bzoj3427小P的牧场(斜率优化dp)
    UVA10559 Blocks(区间dp)
    LOJ6089 小Y的背包计数问题(根号优化背包)
    [APIO2008]免费道路(生成树)
    bzoj4383(拓扑排序)
    [HEOI2014]平衡(整数划分数)
  • 原文地址:https://www.cnblogs.com/qianxuebing/p/9829434.html
Copyright © 2020-2023  润新知