Home > Web Front-end > JS Tutorial > Example of countdown program based on JS_javascript skills

Example of countdown program based on JS_javascript skills

WBOY
Release: 2016-05-16 15:49:23
Original
1227 people have browsed it

The example in this article describes the countdown program based on JS. Share it with everyone for your reference. The specific implementation method is as follows:

剩余时间:<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>

Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template