Heim > Fragen und Antworten > Hauptteil
<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body onload="set()">
<h2>操作成功</h2>
<div id="time"></div>
<span>秒后回到主页</span>
<span onclick="window.history.back()" style="text-decoration:underline">返回</span>
<script type="text/javascript">
var t=5;
function set()
{
var x= setTimeout("set()",1000);
document.getElementById("time").innerHTML=x;
t--;
if(t==0)
{
window.history.back();
}
}
</script>
</body>
</html>
巴扎黑2016-12-21 10:32:13
document.getElementById("time").innerHTML=t; //应该是t,x是用来清除setTimeout()的
var x= setTimeout("set()",1000);
注意顺序,先改变t,再重新调用setTimeout。