美文网首页
js:倒计时(天时分秒)

js:倒计时(天时分秒)

作者: 思无邪cc | 来源:发表于2017-03-07 15:12 被阅读503次

    html代码(简化):

    <b id="time_b"></b>
    

    js代码:

    function ShowCountDown(jztime,divname) { 
        var now = new Date(); 
        var endDate = new Date(Date.parse(jztime.replace(/-/g, "/"))); 
        var leftTime=endDate.getTime()-now.getTime(); 
        var leftsecond = parseInt(leftTime/1000); 
        var day1=Math.floor(leftsecond/(60*60*24)); 
        var hour=Math.floor((leftsecond-day1*24*60*60)/3600); 
        var minute=Math.floor((leftsecond-day1*24*60*60-hour*3600)/60); 
        var second=Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60);
        if(day1 < 10){day1 = "0"+day1;}
        if(hour < 10){hour = "0"+hour;}
        if(minute < 10){minute = "0"+minute;}
        if(second < 10){second = "0"+second;}
        var cc = document.getElementById(divname); 
        cc.innerHTML = "剩余:<em class='wxmr4'>"+day1+"</em>天<em class='wxml4'>"+hour+"</em>:<em>"+minute+"</em>:<em>"+second+"</em>"; 
    } 
    window.setInterval(function(){ShowCountDown('<%=engTime%>','time_b');}, 1000);
    

    相关文章

      网友评论

          本文标题:js:倒计时(天时分秒)

          本文链接:https://www.haomeiwen.com/subject/jpumgttx.html