<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>定时器</title> </head> <body> <p>每500毫秒执行一次,共10次</p> <script> //设置时钟函数,每500毫秒重复执行一次,执行10次后清除时钟 var num=0; var max=10; var intervalId=null; function incrementNumber(){ num++; if(num==max){ clearInterval(intervalId); alert("Done"); } } intervalId=setInterval(incrementNumber,500); </script> </body> </html>
时间: 2024-10-24 04:53:14