首页 > 其他 > 详细

倒计时

时间:2019-11-23 18:38:33      阅读:62      评论:0      收藏:0      [点我收藏+]
这是css:
  <style>
    .box{color:red;
      width:80%;
      margin: 50px auto;
      font-size: 45px}
  </style>
 
这是HTML代码:
  <div class="box"></div>
 
 
这是js代码:
        var div = document.querySelector(".box");
        var timer = setInterval(count, 1)

        function count(){
            var a = new Date().getTime();
            var b = new Date("2019/1/1 00:00:00").getTime();
            var arr = b - a;

            var one = parseInt(arr / 1000 / 60 / 60 / 24);
            var two = parseInt(arr / 1000 / 60 / 60 % 24);
            var three = parseInt(arr / 1000 / 60 % 60);
            var four = parseInt(arr / 1000 % 60);

            one = one < 10 ? "0" + one : one;
            two = two < 10 ? "0" + two : two;
            three = three < 10 ? "0" + three : three;
            four = four < 10 ? "0" + four : four;


            div.innerHTML = "今年还剩下" + one + "天" +  two + "时" + three + "分" + four + "秒";

        }

倒计时

原文:https://www.cnblogs.com/fuxiaoyon/p/11919025.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!