js倒计时器+防止刷新

//读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();	
		}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值