ajila
2017-01-07 19:50
<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
<!--先编写好网页布局-->
<h3>操作成功</h3>
<p>
<span id="countdown">5</span> 秒后回到主页
<a href="#tag1" onclick="goBack()">返回</a>
<a name="tag1"></a>
</p>
<script type="text/javascript">
//获取显示秒数的元素,通过定时器来更改秒数。
var num = 5;
function countdownTimer(){
num--;
document.getElementById("countdown").innerHTML = num;
if(0==num)
{
num = 5;
location = "http://www.imooc.com";
}
}
var int = setInterval(countdownTimer,1000);
//通过window的location和history对象来控制网页的跳转。
function goBack(){
clearTimeout(int);
history.back();
}
</script>
</body>
</html>
你的代码我调试了一下,发现在火狐、谷歌、IE上均没有问题(在我的电脑上)。
JavaScript进阶篇
469185 学习 · 22584 问题
相似问题