NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
js定时器有两种 setTimeout(): 是指定的毫秒后调用函数或计算的方法 ~~~ <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>hello</title> </head> <body> <p>点击按钮,在等待 3 秒后弹出 "Hello"。</p> <button onclick="myFunction()">点我</button> <script> function myFunction() {     setTimeout(function(){alert("Hello")},3000); } </script> </body> </html> ~~~ setInterval() :按照指定的周期(以毫秒计)来调用函数或计算表达式。方法会不停地调用函数,直到 clearInterval() 被调用或窗口被关闭 ``` <input type="text" id="clock"> <button>停止</button> <script> var int = self.setInterval("clock()",5000); function clock(){ var d = new Date(); var t = d.toLocaleTimeString(); document.getElementById("clock").value = t; } </script> ```