使用es6 let特性做一个倒计时页面

时间:2021-06-08 22:03:57
 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4   <meta charset="UTF-8">
 5   <title>countdown</title>
 6 </head>
 7 <body>
 8   <div id="showtime"></div>
 9   <script>
10   "use strict"
11   {
12     let showtime = document.getElementById('showtime');
13     let countdown=(dom,num)=>{
14       for(let i=num;i>0;i--){
15         setTimeout(()=>{
16           dom.innerText=i
17           console.log(i)
18         },(num-i+1)*1000)
19       }
20     }
21     countdown(showtime,5)
22   }
23   </script>
24 </body>
25 </html>