沒(méi)思路的可以看看我的,可能沒(méi)那么好,但功能還是做出來(lái)了
<!DOCTYPE html>
<html>
<head>
<title>瀏覽器對(duì)象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb" />
</head>
<style type="text/css">
#icon {
position: absolute;
}
</style>
<body>
<!--先編寫(xiě)好網(wǎng)頁(yè)布局-->
<h3>操作成功</h3>
<span id="icon">5</span>
<p> s后回到主頁(yè)<a href="#">返回</a></p>
<script type="text/javascript">
var dom = document.getElementById("icon");
var time = setInterval(clock, 5000)
//獲取顯示秒數(shù)的元素,通過(guò)定時(shí)器來(lái)更改秒數(shù)。
var time1 = setTimeout(click, 1000)
function clock() {
window.location.assign("https://www.baidu.com/")
window.location.href("https://www.baidu.com/")
}
var a = 5;
function click() {
//判斷如果a = 0就終止循環(huán)
if (a == 0) {
clearTimeout(time1);
} else {
document.getElementById("icon").value = a;
a--
console.log(a)
time1 = setTimeout(click, 1000) //當(dāng)a - 1 之后繼續(xù)執(zhí)行setTimeout函數(shù)
document.getElementById("icon").innerHTML = a; //把a(bǔ)的值實(shí)時(shí)的賦給HTML元素,從而改變頁(yè)面上的數(shù)字
}
}
//通過(guò)window的location和history對(duì)象來(lái)控制網(wǎng)頁(yè)的跳轉(zhuǎn)。
</script>
</body>
</html>