以下代码是包含计时器和其他2个函数的javascript
`
var sec;
var min;
var counter = setInterval(timer,1000); // 1000每1秒运行一次
//set the timer to the session variable only for the first time
if(isPostBack == 'false'){
sec=second;
min=minute;
}
//set the timer
function timer()
{
if(isPostBack == 'true')
{
sec = second;
min = minute;
}
sec=sec-1;
if(sec < 0)
{
sec=59;
min--;
}
else
{
min=min;
}
if(sec <=9 )
{
sec = "0"+sec;
}
document.getElementById("lblCountDown").innerHTML= "Time Left: "+(min<=9 ? "0" + min : min)+" mins"+" "+sec + " secs";
//copy the value of min and sec in fields
document.getElementById("min").value=min;
document.getElementById("sec").value=sec;
//copy the value of min and sec in session variable
minute = min;
second = sec;
if (min <=0 && sec <= 0)
{
clearInterval(counter);
alert("Times Up!!!. Your Test Will Be Auto Submited");
document.getElementById("Submit").click();
return;
}
}
function showKeyCode(e)
{
var keycode =(window.event) ? event.keyCode : e.keyCode;
if(keycode == 116)
{
alert("Page Cannot be refresh");
event.keyCode = 0;
event.returnValue = false;
return false;
}
}
function disableBackButton()
{
window.history.forward(1);
}
` aspx.cs文件中的代码
`<body onload = "disableBackButton()" onkeydown = "showKeyCode()">
后退按钮没有被禁用 任何人都可以提出解决方案吗?
答案 0 :(得分:0)
该代码不会禁用后退按钮!
该代码必须在上一页。