復制代碼 代碼如下:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>5秒後跳轉到另一個頁面</title>
<script type="text/javascript">
var t = 5;
function countDown(){
var time = document.getElementById("time");
t--;
time.value=t;
if (t<=0) {
location.href="http://www.baidu.com";
clearInterval(inter);
};
}
var inter = setInterval("countDown()",1000);
//window.onload=countDown;
</script>
</head>
<body onload="countDown()">
<input type="text" readonly="true" value="5" id="time"/>
<!--也可以在這裡寫javascript代碼,這樣就不必在body標簽中寫onload="countDown()"。-->
</body>
</html>