1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <title>setTimeout</title> 5 </head> 6 <body> 7 <h1>跳转页面</h1> 8 <form> 9 <div> 10 <p><span id="skip"></span>秒后跳转到主页面</p> 11 </div> 12 </form> 13 <script type="text/javascript"> 14 var t = 5; 15 function showTime() { 16 t -= 1; 17 document.getElementById(‘skip‘).innerHTML = t; 18 if (t == 0) { 19 window.location.href = ‘http://www.baidu.com‘; 20 } 21 setTimeout("showTime()",1000); 22 } 23 showTime(); 24 </script> 25 </body> 26 </html>