摄影祖师爷
2017-09-21 09:31
<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
<!--先编写好网页布局-->
<p>操作成功</p>
<span id="second">5</span><span>秒后回到主页</span><a href="http://www.imooc.com/qadetail/236877">返回</a>
<script type="text/javascript">
var second=document.getElementById("second").innerHTML;
function method(){
second--;
document.getElementById("second").innerHTML=second;
if(second==0){
location.assign("http://www.imooc.com/qadetail/236877");
}
}
//获取显示秒数的元素,通过定时器来更改秒数。
setInterval(method,1000);
//通过window的location和history对象来控制网页的跳转。
</script>
</body>
</html>
因为那个定时器的意思是,过多少时间执行一次函数,执行一次函数method()那个数字才会发生变化。
JavaScript进阶篇
468692 学习 · 21895 问题
相似问题