有人可以给我一个例子或任何教程,会有帮助吗? THX
答案 0 :(得分:2)
这样的事情应该让你开始:
var remindTimer;
function remind() {
$.ajax({
url : '/getData.php',
success : function(data) {
alert(data);
}
});
}
function restartRemindTimer() {
clearTimeout(remindTimer);
remindTimer = setTimeout(remind, 1800000); // 30 min
}
$(document).on('mousemove keypress', restartRemindTimer);
答案 1 :(得分:0)
当然可以......
<script type="text/javascript">
idleTime = 0;
$(document).ready(function () {
//Increment the idle time counter every minute.
var idleInterval = setInterval("timerIncrement()", 60000); // 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 > 29) { // 30 minutes
$(selector).load(url); // or perform ajax request
}
}
</script>