<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="box"></div>
<script>
var box = document.getElementById("box");
var count = 5;
var speed = 1000;
setTimeout(go,speed);
function go() {
count--;
box.innerHTML = "<a href='http://www.baidu.com'>页面将在" + count + "秒后跳转页面</a>";
if(count <= 0){
window.location.href = "http://www.baidu.com";
}else{
setTimeout(arguments.callee,speed); // 递归调用
}
}
</script>
</body>
</html>
arguments.callee:
返回正在执行的函数,只能在函数体内使用,在使用函数递归调用时,推荐使用arguments.callee代替函数名本身