主要使用setInterval函数
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <title></title> <script type="text/javascript"> var i = 5; var intervalid; intervalid = setInterval("fun()", 1000); function fun() { if (i == 0) { window.location.href = "http://www.baidu.com"; clearInterval(intervalid); } document.getElementById("mes").innerHTML = i; i--; } </script> </head> <body> <p>还 <span id="mes">5</span> 秒跳转</p> </body> </html>