jQuery Countdown插件重启

tim*_*imG 3 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
    });
}
Run Code Online (Sandbox Code Playgroud)

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

谁可以帮助我?

jas*_*_89 5

在以下行的startResetCounter函数之上添加:

$('.reset_counter div').countdown('destroy'); //remove countdown if it was already used
Run Code Online (Sandbox Code Playgroud)

所以最后你会得到:

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

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