基于jQuery+Cookie实现的防止刷新的在线考试倒计时_jquery
程序员文章站
2022-03-13 21:16:49
...
基于jQuery+Cookie实现的防止刷新的在线考试倒计时
$(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
以上所述就是本文的全部内容了,希望大家能够喜欢。