0

我知道的

setInterval至少在 IE9 中,如果没有 self 包含参数,则无法将参数传递给方法。

myInterval = setInterval('startTimer(10)',500);行不通

然而

setInterval( function() { startTimer(10); }, 500 );将工作。

我尝试过的

    timer( $('#display-upgrade-ticker-'+response.userClubHouseDisplayId + " .display-upgrade-timer"),currentDate);

    function timer(Obj, target_date) {

        // variables for time units
        var days, hours, minutes, seconds;

        displayInterval = setInterval(function () {
            // update the tag with id "countdown" every 1 second
            var current_date = new Date().getTime();
            var seconds_left = (target_date.getTime() - current_date) / 1000;
            console.log(seconds_left);
            // do some time calculations
            days = Math.round(parseInt(seconds_left / 86400));
            seconds_left = Math.round(seconds_left % 86400);

            hours =Math.round(parseInt(seconds_left / 3600));
            seconds_left = Math.round(seconds_left % 3600);

            minutes = Math.round(parseInt(seconds_left / 60));
            seconds = Math.round(parseInt(seconds_left % 60));

            // format countdown string + set tag value
            if(hours<10) hours='0'+hours;
            if(minutes<10) minutes='0'+minutes;
            if(seconds<10) seconds='0'+seconds;

            $(Obj).html(hours+":"+minutes + ":" + seconds);

            if ( days == 0 && hours == 0 && minutes == 0 && seconds == 0 ) {
                clearInterval(displayInterval);        
            }
        },1000);
    }

我想要的是

我需要在if ( days == 0 && hours == 0 && minutes == 0 && seconds == 0 )满足条件后触发 clearInterval。如果 setInterval 是自包含的,我该怎么做。

4

0 回答 0