純js實現10分鍾倒計時


一個簡單實現倒計時的小栗子~

效果圖:簡陋的不能再簡陋了,捂臉

代碼:

 1 <!DOCTYPE HTML>
 2 <html>
 3 <head>
 4     <title> 倒計時 </title>
 5     <meta  charset="utf-8">
 6     <script type="text/javascript">
 7         window.onload = function(){
 8             var m = 9;  //分
 9             var s = 59;  //秒
10             var countdown = document.getElementById("title");
11             getCountdown();
12             setInterval(function(){ getCountdown() },1000);
13             function getCountdown (){
14                 countdown.innerHTML = "<span>"+m+"</span> :<span>"+s+"</span>";
15                 if( m == 0 && s == 0 ){
16                     alert("倒計時結束");
17                     m = 9;
18                     s = 59;
19                 }else if( m >= 0 ){
20                     if( s > 0 ){
21                         s--;
22                     }else if( s == 0 ){
23                         m--;
24                         s = 59;
25                     }
26                 }
27             }
28         }
29     </script>
30 </head>
31 <body>
32     <h1>倒計時</h1>
33     <div id="title"></div>
34 </body>
35 </html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM