jQuery Countdown插件重启

时间:2012-09-26 13:16:49

标签: jquery plugins timer countdown

我正在使用jQuery Countdown插件(http://keith-wood.name/countdown.html),但我似乎无法重置计时器。

单击按钮时,下面的功能将开始倒计时:

function startResetCounter() {
    $('.reset_counter div').countdown({ 
        until: '+3m +0s',
        compact: true,
        format: 'MS',
        onExpiry: resetPage
    });
}

但是当我按下按钮时,它不会重置计时器。

任何可以帮助我的人?​​

1 个答案:

答案 0 :(得分:5)

startResetCounter 函数之后添加以下行:

$('.reset_counter div').countdown('destroy'); //remove countdown if it was already used

所以最后你会得到:

function startResetCounter() {
    $('.reset_counter div').countdown('destroy');

    $('.reset_counter div').countdown({ 
       until: '+3m +0s',
       compact: true,
       format: 'MS',
       onExpiry: resetPage
    });
}