分倒计时js

2020-07-03  本文已影响0人  森森deHOME
<!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>
上一篇下一篇

猜你喜欢

热点阅读