利用Cookie防止刷新的在线考试倒计时JS代码
程序员文章站
2024-02-02 12:09:46
...
$(function() { var _minute = parseInt("${exampaper.paperTime }"); var _expiresHours = _minute * 60 * 1000; if(!hasSetCookie()){ addCookie("${examinee.examineeId}", _expiresHours, _expiresHours); } settime($("#remainTime")); }); function hasSetCookie(){ var strCookie = document.cookie; var arrCookie = strCookie.split("; "); for (var i = 0; i 0) { var date = new Date(); date.setTime(date.getTime() + expiresHours * 1000); cookieString = cookieString + ";expires=" + date.toUTCString(); } document.cookie = cookieString; } //修改cookie的值 function editCookie(name, value, expiresHours) { var cookieString = name + "=" + escape(value); if (expiresHours > 0) { var date = new Date(); date.setTime(date.getTime() + expiresHours * 1000); //单位是毫秒 cookieString = cookieString + ";expires=" + date.toGMTString(); } document.cookie = cookieString; } //根据名字获取cookie的值 function getCookieValue(name) { var strCookie = document.cookie; var arrCookie = strCookie.split("; "); for (var i = 0; i