1.利用setInterval
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<title>jump.html</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="refresh" content="5;url=runoob.html">
</head>
<body οnlοad=timer()>
name and url error,page will jump in <span id="spanId">5</span> seconds. <br>
</body>
<script type="text/javascript">
var x = 5;
function run(){
var span = document.getElementById("spanId");
x--;
span.innerHTML = x;
}
function timer(){
window.setInterval("run()",1000);
}
</script>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<title>jump1.html</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="refresh" content="5;url=runoob.html">
</head>
<body οnlοad=run()>
name and url error,page will jump in <span id="spanId"></span> seconds. <br>
</body>
<script type="text/javascript">
var x = 5;
function run(){
var span = document.getElementById("spanId");
span.innerHTML = x;
x--;
window.setTimeout(run,1000);
/* 上面一句也可以用以下替换
window.setTimeout("run()",1000);*/
}
</script>
</html>