编写body
<p><span id="time" >5</span>秒后页面自动跳转至主页...</p>
编写script
<script>
var second = 5;
var time = document.getElementById("time");
function showtime() {
second--;
if (second<=0){
location.href="https://www.baidu.com";
}
time.innerHTML = second +"";
}
setInterval(showtime,1000);
</script>
全部代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>跳转页面</title>
</head>
<body>
<p><span id="time" >5</span>秒后页面自动跳转至主页...</p>
<script>
var second = 5;
var time = document.getElementById("time");
function showtime() {
second--;
if (second<=0){
location.href="https://www.baidu.com";
}
time.innerHTML = second +"";
}
setInterval(showtime,1000);
</script>
</body>
</html>