沐沉初
2016-02-29 20:50
有没有人在调试8.17那个编程练习的时候,越到这种情况,代码已经编写完成,一打开那个页面,几秒的时候,就会跳转到前一个页面,想要取消操作也不行,求各位大神指教?
那个编程练习本身就是需要做一个自动跳转的中转页面,无法取消,如果不在5s内点击后退,那么就只能返回慕课网主页。不清楚你的程序代码到底是什么样的,不过按说应该是框架右侧的页面出现跳转。下面是我写的代码,和答案的好几个实现方式都不太一样,你可以参考和比较一下。
<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
<!--先编写好网页布局-->
<h2>操作成功</h2>
<h4><span id="sec">5</span>秒后回到主页 <a href="javascript:goBack()">返回</a></h4>
<script type="text/javascript">
var second = 5;
//获取显示秒数的元素,通过定时器来更改秒数。
function count(){
var myurl = "http://"+window.location.hostname;
if(second>0){
document.getElementById("sec").innerHTML = second;
second--;
setTimeout("count()",1000);
}
else{
window.location.href ="myurl";
}
}
setTimeout("count()",1000);
//通过window的location和history对象来控制网页的跳转。
function goBack(){
window.history.go(-1);
}
</script>
</body>
</html>JavaScript进阶篇
469145 学习 · 22584 问题
相似问题