为了账号安全,请及时绑定邮箱和手机立即绑定

重置setTimeout

重置setTimeout

慕少森 2019-12-20 11:15:08
我有以下几点:window.setTimeout(function() {    window.location.href = 'file.php';}, 115000);如何通过.click函数在倒计时中途重置计数器?
查看完整描述

3 回答

?
GCT1015

TA贡献1827条经验 获得超4个赞

您可以存储对该超时的引用,然后调用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(...);


查看完整回答
反对 回复 2019-12-20
?
烙印99

TA贡献1829条经验 获得超13个赞

您将必须记住超时“ Timer”,将其取消,然后重新启动:


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();

}


查看完整回答
反对 回复 2019-12-20
  • 3 回答
  • 0 关注
  • 801 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信