JavaScript,setInterval,setTimeout,定时器

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/czh500/article/details/84945918

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>

猜你喜欢

转载自blog.csdn.net/czh500/article/details/84945918