終于解決了
<!DOCTYPE html>
<html>
<head>
<title>瀏覽器對象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb" />
</head>
<body>
<!--先編寫好網頁布局-->
<h3>操作成功</h3>
<label id="second">5</label>
<span>秒后回到主頁</span>
<a href="http://www.xianlaiwan.cn" target="_self">返回</a>
<script type="text/javascript">
var time = 5;
function clock() {
//獲取顯示秒數的元素,通過定時器來更改秒數。
document.getElementById("second").innerHTML = time;
time = time - 1;
if(time==-1){
clearInterval(i);
window.location.href="http://www.xianlaiwan.cn";
}
}
i=setInterval(clock, 1000);
//通過window的location和history對象來控制網頁的跳轉。
</script>
</body>
</html>
2019-11-19
<!DOCTYPE?html><html>?<head>??<title>瀏覽器對象</title>????<meta?http-equiv="Content-Type"?content="text/html;?charset=gkb"/>???<style?type="text/css">??????#timeStep?{??????????font-weight:bold;??????}??????.backStyle?{??????????color:blue;??????????text-decoration:underline;??????}??</style>??</head>?<body>??<!--先編寫好網頁布局-->??<h2>操作成功</h2>????<p><span?id="timeStep">5</span>秒后回到主頁?<span?class="backStyle"?onclick="goback()">返回</span></p>???<script?type="text/javascript">????var?stepDom?=?document.getElementById("timeStep");??var?step?=?parseInt(stepDom.innerText);??var?stepInterval?=?setInterval(onload,?1000);??function?onload()?{????step?=?step-1;????stepDom.innerText?=?step;??????if?(step?==?1)?{??????????clearInterval(stepInterval);??????????window.open("http://www.xianlaiwan.cn",?"_blank");??????}??}??function?goback()?{??????window.history.back();??}?</script>?</body></html>