我有以下几点:
window.setTimeout(function() {
window.location.href = 'file.php';
}, 115000);
如何通过.click函数在倒计时中途重置计数器?
发布于 2009-09-24 16:15:09
您可以存储对该超时的引用,然后对该引用调用clearTimeout
。
// in the example above, assign the result
var timeoutHandle = window.setTimeout(...);
// in your click function, call clearTimeout
window.clearTimeout(timeoutHandle);
// then call setTimeout again to reset the timer
timeoutHandle = window.setTimeout(...);
发布于 2009-09-24 16:17:43
你必须记住超时“定时器”,取消它,然后重新启动它:
g_timer = null;
$(document).ready(function() {
startTimer();
});
function startTimer() {
g_timer = window.setTimeout(function() {
window.location.href = 'file.php';
}, 115000);
}
function onClick() {
clearTimeout(g_timer);
startTimer();
}
发布于 2009-09-24 16:14:18
var myTimer = setTimeout(..., 115000);
something.click(function () {
clearTimeout(myTimer);
myTimer = setTimeout(..., 115000);
});
沿着这些路线的东西!
https://stackoverflow.com/questions/1472705
复制相似问题