使用meta实现定时跳转链接

利用了meta标签的一个功能。

HTML:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="5; url=http://www.baidu.com">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>

</head>

<body>
<h1>页面将在 <span id="time">5</span> 秒后重定向</h1>
<script src="111.js"></script>
<form>
<fieldset>
<legend>health information</legend>
height: <input type="text" />
weight: <input type="text" />
</fieldset>
</form>
</body>

</html>

js:

1
2
3
4
5
6
7
8
9
10
11
12
13
let num = document.getElementById('time');
let t = 5
function changeTIme() {
if (t > 0) {
t--;
num.innerHTML = t;
} else {
alert('Time out');
clearInterval(timer);
}
}
let timer = setInterval(changeTIme, 1000);