码迷,mamicode.com
首页 > 其他好文 > 详细

倒计时代码

时间:2016-09-19 19:30:17      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:

<script language="javascript" type="text/javascript"> 
    var interval = 1000;
    function toDb(n){
        if(n<10){
            return ‘0‘+n;
        } else {
            return ‘‘+n;
        }

    }; 
    function ShowCountDown(year,month,day,divname) 
    { 
        var now = new Date(); 
        var endDate = new Date(year, month-1, day); 
        var leftTime=endDate.getTime()-now.getTime(); 
        var leftsecond = parseInt(leftTime/1000); 
        var day1=toDb(Math.floor(leftsecond/(60*60*24))); 
        var hour=toDb(Math.floor((leftsecond-day1*24*60*60)/3600)); 
        var minute=toDb(Math.floor((leftsecond-day1*24*60*60-hour*3600)/60)); 
        var second=toDb(Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60)); 
        var cc = document.getElementById(divname); 
        cc.innerHTML = "距离活动结束,仅剩下 <span class=‘red‘>"+day1+"</span>天 <span class=‘red‘>"+hour+"</span>时 <span class=‘red‘>"+minute+"</span>分 <span class=‘red‘>"+second+"</span>秒";
    }; 
    window.setInterval(function(){ShowCountDown(2016,10,15,‘lastTime‘);}, interval); 
</script> 

 

倒计时代码

标签:

原文地址:http://www.cnblogs.com/vscss/p/5886082.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!