1. 使用setTimeout("fun()", 1000);
ps:此方法在指定ms后会执行且只会执行一次:
故可以用递归调用来实现多次跳转:
2、这里使用setInterval("fun()", 10000); 会一直执行,直到调用clearInterval()
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>js定时跳转页面的方法</title>
</head>
<body>
<script type="text/javascript">
var t = 10; //设定跳转的时间
var intervalid;
setInterval("locate()", 1000); //启动1秒定时 ,会一直执行,直到调用clearInterval
function locate() {
if (t == 0) {
location = "http://www.baidu.com/"; //#设定跳转的链接地址
clearInterval(intervalid);
}
document.getElementById('show').innerHTML = " " + t + " "; // 显示倒计时
t--;
}
</script>
<div id="errorfrm">
<h3>出错啦~~~</h3>
<div id="error">
<img src="images/error.gif" mce_src="images/error.gif" alt="" />
<p>系统出错,请联系管理员!</p>
<p>将在 <span id="show"></span> 秒钟后返回首页!</p>
</div>
</div>
</body>
</html>