日期:2014-05-16  浏览次数:20365 次

剩余时间
剩余时间(倒计时)是怎么做的?期望是能显示天时分,最好能用jquery实现?

------解决方案--------------------
javascript计时器
------解决方案--------------------
设定时间.getTime()-当前时间.getTime()转换成毫秒数后将毫秒转换成天时分秒试试
------解决方案--------------------

<span id="daysLeft"></span>
<script type="text/javascript">
/*
**参数:target(目标日期),类型:string,格式:year/month/day
*/
(function tC(target){

    var day=24*60*60*1000,
        hour=60*60*1000,
        minute=60*1000,
        second=1000;

    var tE=(new Date(target)).getTime(),
        now=new Date(),
        tN=now.getTime(),
        hN=now.getHours(),
        mN=now.getMinutes(),
        sN=now.getSeconds();

    var time=tE-tN,
        _day=parseInt(time/day),
        _hour=parseInt(time%day/hour),
        _minute=parseInt(time%day%hour/minute),
        _seconds=parseInt(time%day%hour%minute/second),
        str='距离 '+target+' 还有: '+_day+'天'+_hour+'时'+_minute+'分'+_seconds+'秒';

    document.getElementById('daysLeft').innerHTML=str;
    setTimeout(function(){tC(target)},1000);
    
})('2013/12/25');

</script>