倒计时

作者: 优秀的人A | 来源:发表于2018-12-04 19:04 被阅读20次
    window.onload = function () {
            var odiv = document.getElementById('div1');
    
            function timeLeft() {
                    var now = new Date();
                    var future = new Date(2018,11,13,0,0,0);
                    var mill = parseInt((future - now) / 1000);
                    var day = parseInt(mill/86400);
                    var hour = parseInt((mill%86400) / 3600);
                    var minute = parseInt(((mill%86400)%3600)/60);
                    var sencond = mill % 60;
    
                    odiv.innerHTML = '距离2018年12月13日00时00分00秒还有' + day + '天'
                + toDouble(hour) + '时' + toDouble(minute) + '分' + toDouble(sencond) + '秒'
             }
             timeLeft();
             setInterval(timeLeft,1000);
        };
    
        function toDouble(num) {
            if(num<10){
                return '0' + num;
            }else{
                return num;
            }
        }
    
    • setTimeout 只执行一次定时器
    • clearTimeout 关闭执行一次定时器
    • setInterval 反复执行定时器
    • clearInterval 关闭反复执行定时器

    相关文章

      网友评论

          本文标题:倒计时

          本文链接:https://www.haomeiwen.com/subject/xlpvcqtx.html