//读Cookie,返回值为相应Cookie的内容
function getCookie(cookieName){
var cookieContent = '';
var cookieAry = document.cookie.split("; ");//得到Cookie数组
for(var i=0;i<cookieAry.length;i++){
var temp = cookieAry[i].split("=");
if(temp[0] == cookieName){
cookieContent = decodeURI(temp[1]);
}
}
return cookieContent;
}
var timelimit = document.getElementById('timelimit').value;
//alert(timelimit);
var maxtime = timelimit*60; //一个小时,按秒计算,自己调整!
function CountDown(){
if(maxtime>=0){
if(getCookie("maxtime") == "")
{
minutes = Math.floor(maxtime/60);
seconds = Math.floor(maxtime%60);
}else{
//alert(document.cookie);
maxtime = getCookie("maxtime");
minutes = Math.floor(maxtime/60);
seconds = Math.floor(maxtime%60);
}
msg = "距离考试结束结束还有<a style='font-size:20px;font-weight:bold;color:red;padding:4px;'>"+minutes+"分"+seconds+"秒</a>";
document.all["timer"].innerHTML=msg;
if(maxtime == 5*60)
alert('注意,还有5分钟!');
--maxtime;
document.cookie = "maxtime="+ encodeURI(maxtime);
}else{
clearInterval(timer);
alert("时间到,结束!");
document.cookie = "maxtime"+"=;expires="+(new Date(0)).toGMTString();
document.getElementById('examform').submit();
}
}
js倒计时器+防止刷新
最新推荐文章于 2023-03-20 10:24:59 发布