setInterval方法:
<html> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>出错啦~~~</title> <link href="css/login1.css" mce_href="css/login1.css" rel="stylesheet" type="text/css" /> <script language="javascript" type="text/javascript"> var i = 5; var intervalid; intervalid = setInterval("fun()", 1000); function fun() { if (i == 0) { location.href = "http://www.baidu.com"; //location.replace(‘http://www.baidu.com‘) clearInterval(intervalid); } document.getElementById("mes").innerHTML = i; i--; } </script> </head> <body> <div id="errorfrm"> <h3>出错啦~~~</h3> <div id="error"> <img src="images/error.gif" mce_src="images/error.gif" alt="" /> <p>系统出错,请联系管理员!</p> <p> 将在 <span id="mes">5</span> 秒钟后返回首页! </p> </div> </div> </body> </html>
setTimeout()方法:
<html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <script type="text/javascript"> var c=0 var t function timedCount() { document.getElementById(‘txt‘).value=c c=c+1 t=setTimeout("timedCount()",1000)//调用函数本身 } function stopCount() { clearTimeout(t) } </script> </head> <body> <form> <input type="button" value="Start count!" onClick="timedCount()"> <input type="text" id="txt"> <input type="button" value="Stop count!" onClick="stopCount()"> </form> </body> </html>
跳转的两种实现方法setInterval和setTimeout,布布扣,bubuko.com
跳转的两种实现方法setInterval和setTimeout
原文:http://www.cnblogs.com/liu-l/p/3835945.html