js 定时器有以下两个方法:
举获取当前时间的例子
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div id="screen"> 时间 </div> </body> </html> <script> var screen=document.getElementById('screen') function getTime() { screen.innerHTML=new Date().toLocaleTimeString() } getTime() setInterval(getTime,1000) </script>