js计时器

Posted JunviZeng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js计时器相关的知识,希望对你有一定的参考价值。

<script>
            var t = null
            t = setTimeout(time,1000)//开始运行
            function time(){
                clearTimeout(t)//清除定时器
                dt = new Date()
                var y = dt.getFullYear()
                var m = dt.getMonth() + 1
                var d = dt.getDate()    
                var h = dt.getHours()    
                var M = dt.getMinutes()    
                var s = dt.getSeconds()    
                document.querySelector(".time").innerhtml = "当前时间:" + y + "年" + m + "月" +
                d + "日" + h + "时" + M + "分" + s + "秒"
                t = setTimeout(time , 1000)//设定定时器,循环运行
            }
</script>

 

以上是关于js计时器的主要内容,如果未能解决你的问题,请参考以下文章