setTimeout()只执行一次,然后就不跳动了


function countDown($class){
    var t = $($class).attr("endTime");
    var targetTime = new Date(t);
    targetTime = targetTime.getTime();
    var nowTime = new Date();
    nowTime = nowTime.getTime();
    reflash($class,targetTime,nowTime);
}

function reflash(_class,targetTime,nowTime){
    var _second = 1000;
    var _minute = _second * 60;
    var _hour = _minute * 60;
    var _day = _hour * 24;
    var difference = targetTime - nowTime;
    var days = Math.floor(difference / _day);
    var hours = Math.floor((difference % _day) / _hour);
    var minutes = Math.floor((difference % _hour) / _minute);
    var second = Math.floor((difference % _minute)/_second);
    var lastTime = "<i></i>剩余"+days+"天"+nol(hours)+"时"+nol(minutes)+"分"+nol(second)+"秒";
    $(_class).html(lastTime);  

    var t = setTimeout(function(){
        reflash(_class,targetTime,nowTime)
    },1000);
}

countDown($(".residual_time"))

Godco
浏览 2117回答 1
1回答

柠檬酸钠

把setTimeout换成setInterval试一试
打开App,查看更多内容
随时随地看视频慕课网APP