<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
<!--先编写好网页布局-->
<h2>操作成功</h2>
<p><span id="ctime" >5</span>回到主页<a href="back()">返回<a/></p>
<script type="text/javascript">
var index = window.location.host;
var num = document.getElementById("ctime").innerHTML;
function count(){
num = num - 1;
document.getElementById("ctime").innerHTML=num;
if(num == 0){
location.assign("www.imooc.com") ;
}
}//获取显示秒数的元素,通过定时器来更改秒数。
setTimeout("count()",1000);
function back(){
window.history.back()
}
//通过window的location和history对象来控制网页的跳转。
</script>
</body>
</html>你要用setInterval() 同学 setTimeout 只会触发一次
里面最后加一个setTimeout
<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb" />
</head>
<body>
<!--先编写好网页布局-->
<h2>操作成功</h2>
<p><span id="ctime" >5</span>回到主页<a href="back()">返回</a></p>
<script type="text/javascript">
var index = window.location.host;
var num = document.getElementById("ctime").innerHTML;
function count() {
num = num - 1;
document.getElementById("ctime").innerHTML = num;
if (num == 0) {
location.assign("www.imooc.com");
}
}
//获取显示秒数的元素,通过定时器来更改秒数。
//setTimeout不会重复
//setTimeout("count()", 1000);
//SetInterval为自动重复
setInterval("count()", 1000);
//通过window的location和history对象来控制网页的跳转。
function back() {
window.history.back()
}
</script>
</body>
</html><!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
<!--先编写好网页布局-->
<p>操作成功</p></br>
<span id="count">5</span>
<p>秒后回到主页
<input type="button" value="返回" onclick="goback()">
</p>
</br>
<script type="text/javascript">
var num=document.getElementById("count").innerHTML;
//获取显示秒数的元素,通过定时器来更改秒数。
function startCount(){
document.getElementById("count").innerHTML=num;
num=num-1;
if(num==0)
location.assign("www.imooc.com");
}
//通过window的location和history对象来控制网页的跳转。
setInterval("startCount()",1000);
function goback(){
window.history.go(-1);
}
</script>
</body>
</html>