<form id="frm" action="">
考试还剩余<div id="time"></div>
</form>
<script>
var times = 45 * 60;//剩余时间,单位秒
var timeDiv = document.getElementById("time");
var timeObj = null;
function timer(){
if(times == 0){
//倒计时结束,提交表单
document.getElementById("frm").submit();
window.clearInterval(timeObj);
return;
}
var t = Math.floor(times/60) +"分"+times%60+"秒"
timeDiv.innerHTML = t;
times --;
}
timeObj = window.setInterval(timer,1000);
</script>
考试还剩余<div id="time"></div>
</form>
<script>
var times = 45 * 60;//剩余时间,单位秒
var timeDiv = document.getElementById("time");
var timeObj = null;
function timer(){
if(times == 0){
//倒计时结束,提交表单
document.getElementById("frm").submit();
window.clearInterval(timeObj);
return;
}
var t = Math.floor(times/60) +"分"+times%60+"秒"
timeDiv.innerHTML = t;
times --;
}
timeObj = window.setInterval(timer,1000);
</script>