有一个goog day,我在倒数计时器中遇到了一些问题
<div style="font-weight: bold; float:right;" id="quiz-time-left"></div>
<script type="text/javascript">
window.onbeforeunload= function() {
setTimeout('document.myForm.submit()',1);
}
</script>
<script type="text/javascript">
var max_time = 10;
var c_seconds = 0;
var total_seconds =60*max_time;
max_time = parseInt(total_seconds/60);
c_seconds = parseInt(total_seconds%60);
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds';
function init(){
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds';
setTimeout("CheckTime()",999);
}
function CheckTime(){
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds' ;
if(total_seconds <=0){
alert("Time Up!"); setTimeout('document.myForm.submit()',1);
} else
{
total_seconds = total_seconds -1;
max_time = parseInt(total_seconds/60);
c_seconds = parseInt(total_seconds%60);
setTimeout("CheckTime()",999);
}
}
init();
</script>
现在我的问题是当我点击刷新时,我没有在此处显示的表单将在没有警报的情况下提交,并且当时间完成时会弹出一个警报框,现在实际上我希望可以得到确认框,是,否让用户选择,但无法做到,那么有人可以帮助我吗?谢谢
<script type="text/javascript">
window.onbeforeunload= function() {
var isOk = confirm("Are you sure?");
if(isOk)
{
setTimeout('document.myForm.submit()',1);
}
}
</script>
但是当我单击 F5 进行刷新时,该框不显示