window.onload用法,JavaScript,setInterval,setTimeout,定时器
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>window.onload用法,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">
<script type="text/javascript">
//设置整个网页鼠标是小手
function setHtmlCursor(){
//document.getElementsByTagName("html").item(0).style.cursor="pointer";
//document.getElementsByTagName("body").item(0).style.cursor="pointer";//测试网页得出鼠标有小手也有指针(测试时用的是谷歌浏览器,其他浏览器没测试)
document.getElementsByTagName("*").item(0).style.cursor="pointer";
}
/*
关于window.onload的用法的话,有很多种用法,具体的可以上网查相关资料,百度搜索window.onload = 用法,也可
以参考http://www.jb51.net/article/43166.htm
https://zhidao.baidu.com/question/171592929.html
http://www.cnblogs.com/wzhiq896/p/5953974.html
因为时间关系,我在这里就没有写window.onload的用法的笔记了,可以按照上面给出的网站查window.onload的用法
*/
//window.onload用法
/*
javascript代码一般最好放在</body>结束之前,以防止页面元素没有渲染完,JS访问不到对象而报错 ,比如下面的这句
话document.getElementById("myTime").value = 5;如果放在<head>标签中,就会造成JS访问不到对象而报错,如
果你想把javascript代码放在<head>标签中,又不想因为JS访问不到对象而报错的话,必须要用window.onload=function(){.....} 包含起来。
*/
var myTimeout;
//window.onload = nowTime;
/*这是第一种写法*/
/*window.onload = function(){
setInputValue();
nowTime();
}
*/
/*这是第二种写法*/
window.onload = showNowTime;
//这里定义一个新的方法,该方法中调用其他2个方法
function showNowTime(){
//setHtmlCursor();
setInputValue();
nowTime();
}
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){
//alert("看看");
document.getElementById("myTime").value = (parseInt(now) - 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);
}
//设置文本框的值
function setInputValue(){
//alert("hello")
//alert("文本框对象 = " + document.getElementById("myTime"));
document.getElementById("myTime").value = 10;
//alert("文本框中的值 = " + document.getElementById("myTime").value);
//alert("world");
}
//调用setInputValue();方法
//setInputValue();
</script>
</head>
<body>
<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>
</body>
</html>