10
0

5_BOM定时函数.html 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. // 定时函数
  11. // window.setTimeout(function(){
  12. // console.log("hello world");
  13. // },3000)
  14. // 定时函数 里面接受两个参数 第一个为回调函数,第二个参数是时间毫秒为单位 1000毫秒=1秒
  15. // setTimeout(function(){
  16. // },3000)
  17. // function foo(){
  18. // console.log("hell world");
  19. // }
  20. // setTimeout(foo,3000);
  21. // clearTimeout()
  22. // 定时函数 他会循环之行 会根据设定的时间 间隔 循环
  23. // setInterval(function(){
  24. // console.log("hello world");
  25. // },1000)
  26. var i = 0;
  27. var set1 = setInterval(function(){
  28. i++;
  29. console.log(i)
  30. if(i==10){
  31. clearInterval(set1);
  32. }
  33. },1000)
  34. </script>
  35. </body>
  36. </html>