1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>倒计时跳转</title> 5 </head> 6 <body> 7 8 <div id="msg"></div> 9 <script> 10 var times=10; 11 function test(){ 12 document.getElementById("msg").innerHTML="页面将在"+times+"后跳转"; 13 times-=1; 14 if(times<=0){ 15 window.clearInterval(doTEST); 16 window.location.href="http://www.baidu.com"; 17 } 18 } 19 var doTEST; 20 window.clearInterval(doTEST); 21 doTest=window.setInterval("test()",1000); 22 </script> 23 24 </body> 25 </html>