一个简单实现倒计时的小栗子~
效果图:简陋的不能再简陋了,捂脸
代码:
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>
时间: 2024-10-01 22:54:50