您现在的位置: 万盛学电脑网 >> 程序编程 >> 脚本专题 >> javascript >> 正文

纯JS实现动态时间显示代码

作者:佚名    责任编辑:admin    更新时间:2022-06-22

 本篇文章主要是对纯JS实现动态时间显示的代码进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助

代码如下: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title>  <script language="javascript">      var t = null;     t = setTimeout(time,1000);//开始执行     function time()     {        clearTimeout(t);//清除定时器        dt = new Date();        var h=dt.getHours();        var m=dt.getMinutes();        var s=dt.getSeconds();        document.getElementById("timeShow").innerHTML =  "现在的时间为:"+h+"时"+m+"分"+s+"秒";        t = setTimeout(time,1000); //设定定时器,循环执行                  }    </script> </head>   <body> <label id="timeShow"></lable> </body> </html>