美文网首页
HTML实时显示时间

HTML实时显示时间

作者: Ben大师 | 来源:发表于2019-08-04 16:04 被阅读0次
    <!doctype html>
    <html lang="zh-cn">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport"
              content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>
    <body>
    <div id="div1"></div>
    <script>
        function time() {
            var date = new Date();
            var hour = date.getHours();
            var minutes = date.getMinutes();
            var seconds = date.getSeconds();
            var str = "现在的时间" + hour + "时" + minutes + "分" + seconds + "秒";
            var div1 = document.getElementById("div1");
            div1.innerHTML = str;
        }
        setInterval(time,1000);
    </script>
    </body>
    </html>
    

    相关文章

      网友评论

          本文标题:HTML实时显示时间

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