1. 程式人生 > >JavaScript,setInterval,setTimeout,定時器

JavaScript,setInterval,setTimeout,定時器

JavaScript,setInterval,setTimeout,定時器

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JavaScript,setInterval,setTimeout,定時器,雪豹軟體工作室</title>
<!--meta標籤和title標籤有利於SEO優化,搜尋引擎抓取  -->
<meta name="keywords" content="JavaScript,java,雪豹軟體工作室">
<meta name="description"
	content="雪豹軟體工作室主要分享java視訊教程及工作室也推出原創免費java視訊教程,當然啦,我們自己也開發軟體產品and彙集java軟體開發知識、IT開發資料,讓我們進可創業,退可求職謀生。我們認真嚴謹,也搞笑活潑,時而犯二,時而機智。天道酬勤!">
<!--利用meta標籤,3秒後重新整理跳轉,這裡的單位是秒  -->
<!--<meta http-equiv="refresh" content="5; url=http://blog.csdn.net/czh500/article/details/53468208">-->
<link rel="stylesheet" type="text/css" href="input.css">
<link rel="stylesheet" type="text/css" href="body.css">
</head>
<body onload="nowTime()">
	<br>
	<br>
	<br>
	<div align="center">
		<h1>請您訪問新的網站
		<a href="http://blog.csdn.net/czh500/article/details/53468208" title="java視訊教程-雪豹軟體工作室">
		雪豹軟體工作室
		</a>
		</h1>
		<h1>系統將在<input id="myTime" value="5" readonly="readonly" size="2">秒後跳轉,如不支援跳轉,請點選<a href="http://blog.csdn.net/czh500/article/details/53468208">這裡</a>!</h1>
	</div>
	<script type="text/javascript">
	/*
	javascript程式碼一般最好放在</body>結束之前,以防止頁面元素沒有渲染完,JS訪問不到物件而報錯 ,比如下面的這句
	話document.getElementById("myTime").value = 5;如果放在<head>標籤中,就會造成JS訪問不到物件而報錯,如
	果你想把javascript程式碼放在<head>標籤中,又不想因為JS訪問不到物件而報錯的話,必須要用window.onload=function(){.....} 包含起來。 
	*/
var myTimeout;
//alert("hello")
//alert("文字框物件 = " + document.getElementById("myTime"));
document.getElementById("myTime").value = 5;
//alert("文字框中的值 = " + document.getElementById("myTime").value);
//alert("world");
function nowTime(){
	//alert("我是nowTime()方法");
	//clearTimeout(myTimeout);
	var now = document.getElementById("myTime").value;
	//alert("now = " + now);
	//var newNow = document.getElementById("myTime").value;
	//alert("now = " + now);
	/*
	if(now == 1){
	//clearTimeout(myTimeout);
	window.location.href = "http://blog.csdn.net/czh500/article/details/53468208";
	//return;
	}
	else{
		document.getElementById("myTime").value = (parseInt(now) - 1);
		myTimeout = setTimeout(nowTime, 1000);
	}
	*/
	
	
	if(now > 1){
		document.getElementById("myTime").value = (parseInt(now) - 1);
		//setTimeout(),這裡的單位是毫秒,1000毫秒=1秒
		myTimeout = setTimeout(nowTime, 1000);
		}
	else{
		window.location.href = "http://blog.csdn.net/czh500/article/details/53468208";
		//window.location.href可以簡寫成location.href,即window可以省略不寫
		}
	//setTimeout("nowTime()", 1000);
}
</script>
</body>
</html>