小星星3221329
2016-05-20 16:56
我的代码运行不出来呢,5秒之后根本不跳转,是什么原因呀?
你沒打上要跳轉到哪裡,在這一段加上數到0時要跳到的網頁
if(num == 0){
clearInterval(timeout);
window.location.href="要跳到的網頁";
}
<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
<!--先编写好网页布局-->
<h2>操作成功</h2>
<span id = "num">5</span>秒后返回主页 <a href="#" onclick = "window.history.back()">返回</a>
<script type="text/javascript">
var num = 5;
function count(){
//获取显示秒数的元素,通过定时器来更改秒数。
document.getElementById("num").innerHTML = num;
//通过window的location和history对象来控制网页的跳转。
if(num == 0){
clearInterval(timeout);
}
num --;
}
var timeout = setInterval(count,1000);
</script>
</body>
</html>JavaScript进阶篇
469057 学习 · 22582 问题
相似问题