<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
<h1>操作成功</h1>
<span id="second">5</span>
<span>秒后回到主页</span>
<a href="http://www.imooc.com/">返回</a>
<script type="text/javascript">
var i=getElementById("second").innerHTML;
//获取显示秒数的元素,通过定时器来更改秒数。
function time()
{
i--;
document.getElementById("second").innerHTML=i;
if(i==0){
location.assign("http://www.imooc.com");
}
}
setInterval("time()",1000);
//通过window的location和history对象来控制网页的跳转。
function his(){
window.history.back();
}
</script>
</body>
</html>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">
var i = 5;
function time() {
document.getElementById("count").value = i;
i = i - 1;
var x;
if (i>=0) {
x = setTimeout("time()", 1000);
} else {
clearInterval(x);
}
}
setTimeout("time()", 1000);
</script>
</head>
<body>
<input id="count" type="text"/>
</body>
</html>
你给i赋值时少写了document.
你不应该这样写啊