可以參考我這個正確答案,當然方法有很多種
<!DOCTYPE html>
<html>
?<head>
? <title>瀏覽器對象</title>??
? <meta http-equiv="Content-Type" content="text/html; charset=gkb"/>? ?
?</head>
?<body>
? <!--先編寫好網(wǎng)頁布局-->
??
? <h3>操作成功</h3>
<p>
<span id="s">
5
</span>
<span>秒后回到主頁</span>
<a href="#" onclick="tiaozhuan()">返回</a>
</p>
?
? ?<script type="text/javascript">??
?
? ?//獲取顯示秒數(shù)的元素,通過定時器來更改秒數(shù)。
var e = document.getElementById("s");
var s = parseInt(e.innerText);
var intervalId;
intervalId = window.setInterval('showS()',1000);
function showS(){
s-=1;
if(s<1){
window.clearInterval(intervalId);
tiaozhuan();
}
e.innerText = s;
}
? ?//通過window的location和history對象來控制網(wǎng)頁的跳轉(zhuǎn)。
? ?function tiaozhuan(){
? if(window.history.length > 0) {
? history.back();
? }
? ?}
?</script>?
</body>
</html>
2019-08-21
主題是5秒會跳轉(zhuǎn)到新的頁面,你這個是5秒后返回到前一個頁面
2019-07-10
//body
<h1>操作成功</h1>
<pre><span id='s'></span>秒回到主頁<h2 id="back" onclick="tiaozhuan()">返回</h2></pre>
?
//<script>
var i=setInterval(jian,1000);
var time=document.getElementById('s');
var num=5;
function jian(){
time.innerHTML=num;
num--;
if(num<0)
{
clearInterval(i);
location.;
}
}
function tiaozhuan(){
if(history.length>0)
history.forward(1);
}
2019-07-01
var? time=5;
?i=setInterval("clock()",1000);
function clock(){
? ? document.getElementById("second").innerText=time;
? ? time--;
? ? if(time<0)
{
? clearInterval(i);
//window.location.assign("http://idcbgp.cn");
? location.href="http://idcbgp.cn";
}
}
//通過window的location和history對象來控制網(wǎng)頁的跳轉(zhuǎn)。
? ?function tiaozhuan(){
history.go(1);
}