Home > Article > Web Front-end > JavaScript implements a simple clock
[html] <html> <head> <title>JS实现简单的时钟</title> <script> function displayTime() { document.getElementById("time").innerHTML = new Date().toTimeString(); } setInterval(displayTime,1000); // 每隔1秒钟调用displayTime函数 </script> </head> <body> <p id="time"></p> </body> </html>