显示当前时间( setInterval() 方法会每秒执行一次函数,类似手表功能)
</html> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>雅爱笔记_www.5devip.com</title> </head> <body> <p>显示当前时间:</p> <p id="shijian"></p> <script> var myVar = setInterval(function(){ myTimer() }, 1000); function myTimer() { var d = new Date(); var t = d.toLocaleTimeString(); document.getElementById("shijian").innerHTML = t; } </script> </body> </html>