js加载倒计时

  <script>
   
  var loadtime=30*60*1000;
  function millisecondToDate(msd){
    var time = parseFloat(msd) / 1000;

        if (time > 60 && time < 60 * 60){
            time = parseInt(time / 60.0) + "分钟" + parseInt(time % 60.0)  + "秒";
        }
        else if (time >= 60 * 60 && time < 60 * 60 * 24){
            time = parseInt(time / 3600.0) + "小时" + parseInt(time / 60.0)+ "分钟" +parseInt(time % 60.0) + "秒";
        }
        else{
            time = parseInt(time) + "秒";
        }
   
    return time;
}

   //加载倒计时
        function initNumLoad(){
      var time;
            loadtime=loadtime-1000;
            if(loadtime < 0){
               clearInterval(interval_id);
            }else{
     time=millisecondToDate(loadtime);
     alert(time);
            }
           
        }
     
   function check(){
      interval_id=setInterval(initNumLoad, 1000);//循环调用
   }

  </script>

你可能感兴趣的:(倒计时)