js07.html 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>案例2</title>
  6. </head>
  7. <body>
  8. <!--
  9. 321跳转百度
  10. innerHtml : 可以识别标签
  11. innerText : 直接翻译成文本
  12. 1. 获取h1标签
  13. 2. 改变 内容 每个1秒
  14. 3. 定时器 setTimeout
  15. -->
  16. <h1 id="h1" ></h1>
  17. <script>
  18. //开启定时器 返回值关闭
  19. let count = 1;
  20. let index = setInterval(function (){
  21. if (count == 3){
  22. clearInterval(index)
  23. //改变地址
  24. location.href = "https://www.baidu.com"
  25. }
  26. //业务逻辑
  27. let h1 = document.getElementById("h1");
  28. //h1添加内容
  29. //h1.innerHTML = "<font color='red'>"+(4-count)+"</font>";
  30. h1.innerText = "<font color='red'>"+(4-count)+"</font>";
  31. //改变标识
  32. count++;
  33. },1000);
  34. </script>
  35. </body>
  36. </html>