用setInterval方法亲测有效,区别于setTimeout之外的方法
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Fucker</title>
</head>
<body>
<h1>操作成功</h1>
<br />
<span id="num1">
5
</span>
秒后回到主页<a href="#" onclick="window.history.back()">返回</a>
<script type="text/javascript">
var obj = document.getElementById("num1");
var i = 5;
function changeValue() {
if (i == 0) {
window.location.replace("https://www.bilibili.com");
} else {
obj.innerHTML = i-1;
i--;
}
}
var j = setInterval(changeValue, 1000);
</script>
</body>
</html>