HTML倒计时简单实现

时间:2023-02-01 22:04:15
HTML倒计时简单实现HTML倒计时简单实现
 1 <!doctype html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Document</title>
 6     <style type="text/css">
 7         h1{
 8             font-size: 50px;
 9             text-align: center;
10         }
11     </style>
12 </head>
13 <body>
14 <h1>倒计时:<span>10</span></h1>
15 <script type="text/javascript" src = "http://libs.baidu.com/jquery/1.10.0/jquery.min.js"></script>
16 <script type="text/javascript">
17     $(document).ready(function(){
18         var e = $("h1 span").first();
19         var i = 9;
20         var interval = setInterval(function(){
21             e.html(i);
22             i--;
23             if(i <= 0){
24                 clearInterval(interval);
25             }
26         },1000);
27     })
28 </script>
29 </body>
30 </html>
View Code