分倒計時js

 倒計時

<!DOCTYPE HTML>
<html>
<head>
  <title> 倒計時 </title>
  <meta  charset="utf-8">
  <script type="text/javascript">
    window.onload = function(){
      var m =1;  //分
      var s = 59;  //秒
      var countdown = document.getElementById("title");
      getCountdown();
      setInterval(function(){ getCountdown() },1000);
      function getCountdown (){
        countdown.innerHTML = "<span>"+m+"</span> :<span>"+s+"</span>";
        if( m == 0 && s == 0 ){
          alert("倒計時結束");
          m = 9;
          s = 59;
        }else if( m >= 0 ){
          if( s > 0 ){
            s--;
          }else if( s == 0 ){
            m--;
            s = 59;
          }
        }
      }
    }
  </script>
</head>
<body>
<h1>倒計時</h1>
<div id="title"></div>
</body>
</html>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章