DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> 基於JS實現的倒計時程序實例
基於JS實現的倒計時程序實例
編輯:關於JavaScript     

本文實例講述了基於JS實現的倒計時程序。分享給大家供大家參考。具體實現方法如下:

剩余時間:<i id="expireTime"></i>
<script type="text/javascript">
  var expire = 2412169;
  var expireTime = function(expires){
    if(expires > 0){
      var second = expires;
    }else{
      var second = "0 分";
      return second;
    }
    var day = hour = min = "";
    if(second>86400){
      day = Math.floor(second/86400)+"天 ";
      second = second%86400;
    }
    if(second>3600){
      hour = Math.floor(second/3600)+"時 ";
      second = second%3600;
    }
    if(second>60){
      min = Math.floor(second/60)+"分 ";
      second = second%60;
    }
    second = second+"秒";
    return day+hour+min+second;
  }
  var timeEle = document.getElementById("expireTime");
  var timer = window.setInterval(function(){
    timeEle.innerHTML = expireTime(expire--);
    if(expire<0){
      clearInterval(timer);
    }
  },1000);
</script>

希望本文所述對大家的javascript程序設計有所幫助。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved