5_BOM定时函数.html 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. // 定时函数 他会循环之行 会根据设定的时间 间隔 循环
  22. // setInterval(function(){
  23. // console.log("hello world");
  24. // },1000)
  25. var i = 0;
  26. var set1 = setInterval(function(){
  27. i++;
  28. console.log(i)
  29. if(i==10){
  30. clearInterval(set1);
  31. }
  32. },1000)
  33. </script>
  34. </body>
  35. </html>