2012-01-17 3 views
5

시나리오는 폼 요소에서 자동 새로 고침 기능을 작성한 것이고 자동 새로 고침 기능을 사용하지 않으려면 로그인 버튼에서 onclick 이벤트를 원합니다.jquery 폼 요소 사용 안 함

자동 새로 고침을 사용 중지 할 수 없으며 페이지가 계속 새로 고침됩니다.

내 코드는 다음과 같습니다

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


}); 
+1

'에서는 setInterval ("timerIncrement는()", 15000)'는'되어야한다 setInterval ("timerIncrement", 15000); and omg, 스크립트에서 몇 개의 오류를 만들 수 있습니까? – Val

+2

사실, 그것은'setInterval (timerIncrement, 15000);'이어야합니다 -'eval is evil! –

+0

@anu 이것은 매우 일반적인 문제이며,'attr' 대신'prop'를 사용하면 작동 할 것입니다. – noob

답변

1

난 당신이 명확에 간격 타이머를 필요로하는 것 같아요 :

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

내가 알아야 할 것은 clearInterval (idleInterval); –

+0

@Nitinvarpe Fixed! 고맙습니다! – falsarella