一个考试系统,想实现在考生切出页面几次之后自动交卷,但是会一直触发onblur无法自动交卷,求指教
<script>
var count = 5;
//window.onbeforeunload = function (event) {
// event.returnValue = "确定离开吗?";
//}
window.onblur = function () {
count--;
if (count > 0) {
var msg = "浏览器失去焦点:" + count + "";
alert(msg);
}
else {
var msg = "已经自动交卷";
alert(msg);
document.getElementById(submit).click;
}
}
</script>
<script>
var count = 5;
//window.onbeforeunload = function (event) {
// event.returnValue = "确定离开吗?";
//}
window.onblur = function () {
count--;
if (count > 0) {
var msg = "浏览器失去焦点:" + count + "";
alert(msg);
}
else {
var msg = "已经自动交卷";
alert(msg);
document.getElementById(submit).click;
}
}
</script>
自动提交前要取消onbeforeunload事件
window.onbeforeunload = null;
event.returnValue = "确定离开吗?";
}
var count=5;
window.onblur = function () {
count--;
if(count>0){
var msg="您离开的次数剩余:"+count;
console.log(msg);
}else if(count==0){
//为什么到0的时候还不停出发已经自动交卷呢?就是因为当点击alert的时候也是属于失焦,会再走一遍这个判断
var msg = "已经自动交卷";
alert(msg);
document.getElementById(submit).click;
}
}