anu*_*anu 5 javascript jquery setinterval clearinterval
场景是我在表单元素上编写了一个自动刷新功能,我想在登录按钮上点击onclick事件来禁用自动刷新功能.
我无法禁用autorefresh,页面仍然刷新.
我的代码是:
$('#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");
});
});
Run Code Online (Sandbox Code Playgroud)
我猜你需要清除间隔计时器:
$(this).click(function (e) {
alert("Hi In click !");
$('#form').attr("disabled","true");
clearInterval(idleInterval);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
263 次 |
| 最近记录: |