JavaScript显示时钟

<html>
    <head>
        <title>日期</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript">
            function showTime(){
                window.setInterval("displayTime()",1000);
            }
            function displayTime(){
                //获取元素节点
                var timeDiv = document.getElementById("timeDiv");
                //获取系统时间
                var time = new Date();
                var strTime = time.toLocaleString();
                //将系统时间设置到div中
                timeDiv.innerHTML = strTime;
            }
        </script>
    </head>
    <body onload="showTime()">
        <div id="timeDiv"></div>
    </body>
</html>

 

posted @ 2016-08-01 23:56  sailor4518  阅读(173)  评论(0)    收藏  举报