像这样的东西:
(function(){
var timer;
function resetTimer(){
clearTimeout(timer);
timer = setTimeout(function(){
alert('No keydown for 10 seconds');
// Call reset timer here if you want the timer to start again
// when the alert is closed
// Otherwise, if you want to stop the timer forever,
// remove the event handler from document.onkeydown
}, 10000);
}
resetTimer();
document.onkeydown = resetTimer;
})();
Run Code Online (Sandbox Code Playgroud)
它假设您没有将任何其他内容绑定到文件keydown侦听器.如果你有,那么你应该使用addEventListener而attachEvent不是.
| 归档时间: |
|
| 查看次数: |
258 次 |
| 最近记录: |