美文网首页JavaScript
简单的实现页面倒计时js

简单的实现页面倒计时js

作者: LuckyS007 | 来源:发表于2017-09-26 11:39 被阅读109次

    简单的实现页面倒计时js

    <script>
        function ShowCountDown(year,month,day,hour,minute,second) {
            var now = new Date();
            var endDate = new Date(year,month-1,day,hour,minute,second);
            var leftTime = endDate.getTime() - now.getTime();
            var dd = parseInt(leftTime / 1000 / 60 / 60 / 24, 10);//计算剩余的天数
            var hh = parseInt(leftTime / 1000 / 60 / 60 % 24, 10);//计算剩余的小时数
            var mm = parseInt(leftTime / 1000 / 60 % 60, 10);//计算剩余的分钟数
            var ss = parseInt(leftTime / 1000 % 60, 10);//计算剩余的秒数
            dd = checkTime(dd);
            hh = checkTime(hh);
            mm = checkTime(mm);
            ss = checkTime(ss);
            document.getElementById("s_day").innerHTML = dd;
            document.getElementById("s_time").innerHTML = hh;
            document.getElementById("s_minute").innerHTML = mm;
            document.getElementById("s_second").innerHTML = ss;
        }
        function checkTime(i) {
            if (i < 10) {
                i = "0" + i;
            }
            return i;
        }
        window.setInterval(function () { ShowCountDown(2017,10,10,00,00,00); }, 1000);
    </script>
    

    相关文章

      网友评论

        本文标题:简单的实现页面倒计时js

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