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 に答える