1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| <!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>
|