首页 >web前端 >js教程 >基于JS实现的倒计时程序实例_javascript技巧

基于JS实现的倒计时程序实例_javascript技巧

WBOY
WBOY原创
2016-05-16 15:49:231201浏览

本文实例讲述了基于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程序设计有所帮助。

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn