Javascript jquery禁用表单元素

Javascript jquery禁用表单元素,javascript,jquery,setinterval,clearinterval,Javascript,Jquery,Setinterval,Clearinterval,场景是,我已经为表单元素编写了一个自动刷新函数,我希望onclick event on login按钮禁用自动刷新函数 我无法禁用自动刷新,页面仍会刷新 我的代码是: $('#form').ready(function () { //Increment the idle time counter every minute. var idleInterval = setInterval("timerIncrement()", 15000); // 1 minute //Zero

场景是,我已经为表单元素编写了一个自动刷新函数,我希望onclick event on login按钮禁用自动刷新函数

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

我的代码是:

$('#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"); 
    });


});

我想您需要清除间隔计时器:

$(this).click(function (e) {
    alert("Hi In click !");
    $('#form').attr("disabled","true"); 
    clearInterval(idleInterval);
});

setInterval(“timerIncrement()”,15000)应为
setInterval(“timerIncrement”,15000)和omg,你能在一个脚本中犯多少错误?实际上,它应该是
setInterval(timerIncrement,15000)-eval是邪恶的@anu这是一个非常常见的问题,请使用
prop
而不是
attr
,它将正常工作。@Nitinvarpe已修复!非常感谢。