1<!DOCTYPE html>
2<html lang="en">
3 <head>
4 <meta charset="UTF-8" />
5 <title>location</title>
6 </head>
7 <body>
8 <a href="http://www.codebetter.cn">支付成功,5秒之后跳转到首页</a>
9 <script>
10 // 1.获取a元素
11 const a = document.querySelector("a");
12 // 2.开启定时器
13 // 3.声明倒计时变量
14 let num = 5;
15 let timer = setInterval(() => {
16 num--;
17 a.innerHTML = `支付成功,${num}秒之后跳转到首页`;
18 if (num === 0) {
19 clearInterval(timer);
20 location.href = "http://www.codebetter.cn";
21 }
22 }, 1000);
23 </script>
24 </body>
25</html>