js分 秒 毫秒 倒计时

2021-01-20  本文已影响0人  MISS_3ca2
<span id="minutes"></span>:<span id="seconds"></span>:<span id="ms"></span>
    <script>
        var maxtime = 2 * 60 *1000;
        window.setInterval(()=>{
            if (maxtime >= 0) {
                var minutes = Math.floor(maxtime / 60/1000);
                var seconds = Math.floor(maxtime/1000 % 60);
                var ms = Math.floor(maxtime % 1000 / 10);
                 
                document.getElementById('minutes').innerHTML = minutes;
                document.getElementById('seconds').innerHTML = seconds;
                document.getElementById('ms').innerHTML = ms;
                // var msg = "距离结束还有" + minutes + "分" + seconds + "秒" + ms + '毫秒';
                maxtime-=10;
                // console.log(msg)
            }else{
                console.log('倒计时结束')
            }
        },10)
    </script>
上一篇下一篇

猜你喜欢

热点阅读