example03.html 782 B

12345678910111213141516171819202122232425262728
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>延迟跳转</title>
  6. </head>
  7. <body>
  8. <h3><span id="counter">5</span>秒钟以后自动跳转到百度</h3>
  9. <script>
  10. var countDown = 5;
  11. var span = document.getElementById('counter');
  12. window.setTimeout(function() {
  13. countDown -= 1;
  14. if (countDown == 0) {
  15. // window对象的location属性代表浏览器地址栏
  16. window.location.href = 'https://www.baidu.com';
  17. } else {
  18. span.textContent = countDown;
  19. // arguments是函数中的隐含对象
  20. // 通过arguments[0]、arguments[1]可以获得函数的参数
  21. // 通过arguments.callee可以获得正在被调用的函数
  22. window.setTimeout(arguments.callee, 1000);
  23. }
  24. }, 1000);
  25. </script>
  26. </body>
  27. </html>