5

场景是我写了一个表单元素自动刷新的函数,我希望登录按钮上的 onclick 事件禁用自动刷新功能。

我无法禁用自动刷新,页面仍然刷新。

我的代码是:

$('#form').ready(function () { //Increment the idle time counter every minute.
    var idleInterval = setInterval("timerIncrement()", 15000); // 1 minute

    //Zero the idle timer on mouse movement.
    $(this).mousemove(function (e) {
        idleTime = 0;
    });
    $(this).keypress(function (e){
        idleTime = 0;
    });
});

function timerIncrement() {
    idleTime = idleTime + 1;
    if (idleTime > 2) { // 20 minutes
        window.location.reload();
    }
}

$('#login').ready(function () {

    alert("working promptly");
    //Zero the idle timer on mouse movement.
    $(this).click(function (e) {
        alert("Hi In click !");
        $('#form').attr("disabled","true"); 
    });


});
4

1 回答 1

1

我猜你需要清除间隔计时器:

$(this).click(function (e) {
    alert("Hi In click !");
    $('#form').attr("disabled","true"); 
    clearInterval(idleInterval);
});
于 2012-01-17T11:39:07.913 回答