我有以下会话时间javascript代码
<script type="text/javascript">
var time;
var sessionTimeout = <%= Session.Timeout %>
function DisplaySessionTimeout() {
document.getElementById("<%= lblSessionTime.ClientID %>").innerText = sessionTimeout;
sessionTimeout = sessionTimeout - 1;
if (sessionTimeout >= 0)
time = window.setTimeout("DisplaySessionTimeout()", 1000);
else {
alert("Your current Session is over.");
}
}
function cleartime() {
clearTimeout(time);
document.onmousemove = cleartime;
document.onkeypress = cleartime;
}
</script>
它可以倒计时。但是当我移动鼠标或按下键时没有任何反应。我希望它在 mousemove 和 keypress 上重置计数器。任何人都可以发现错误吗?