| 12345678910111213141516171819202122232425262728 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>延迟跳转</title>
- </head>
- <body>
- <h3><span id="counter">5</span>秒钟以后自动跳转到百度</h3>
- <script>
- var countDown = 5;
- var span = document.getElementById('counter');
- window.setTimeout(function() {
- countDown -= 1;
- if (countDown == 0) {
- // window对象的location属性代表浏览器地址栏
- window.location.href = 'https://www.baidu.com';
- } else {
- span.textContent = countDown;
- // arguments是函数中的隐含对象
- // 通过arguments[0]、arguments[1]可以获得函数的参数
- // 通过arguments.callee可以获得正在被调用的函数
- window.setTimeout(arguments.callee, 1000);
- }
- }, 1000);
-
- </script>
- </body>
- </html>
|