$ (function () {var _minute = parseint ("${EXAMPAPER.PAPERTIME&NBSP;}"); 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 < arrcookie.length; i++) {var arr = arrcookie[i].split ("="); (arr[0] == "${examinee.examineeid}") {return true;}}; Return false;} Start Countdown Function settime (Remaintime) {var _time = getcookievalue (" 871d31bacfd4451484c5f70f8860c2a9 "); Var _countdown = parseint (Getcookievalue (" ${ Examinee.examineeid})) / 1000;if (_countdown <= 0) {alert ("Exam time to!") "); Endexam ();} else&nbsP {Var _second = _countdown % 60;var _minute = parseint (_countdown / 60) % 60;var _hour = parseint (parseint (_countdown / 60) / ;if (_hour < 10) _hour = "0" + _hour.tostring ();if (_second <&NBSP;10) _second = "0" + _second.tostring ();if (_minute < 10) _minute = "0" + _minute.tostring () remaintime.html (_hour + ":" + _minute + ":" + _second); _countdown--;editcookie ("${examinee.examineeid}", _countdown * 1000, _countdown * 1000);} Executes settimeout (function () {settime (remaintime) every 1000 milliseconds;}, 1000);};/ /Time Add Cookiefunction addcookie (name, value, expireshours) {var cookiestring = name + "=" + escape (value); the //escape () function encodes the string so that it can be read on all computers. Judge whetherSet expiration time, 0 means disable if (expireshours > 0) {var date = new date () when the browser is closed; Date.settime (Date.gettime () + expireshours * 1000); cookiestring = cookiestring + "; expires=" + date.toutcstring ();} document.cookie = cookiestring;} Modify the value of the cookie Function editcookie (name, value, expireshours) {var cookiestring = name + "=" + escape (value);if (expireshours > 0) {var Date = new date ();d ate.settime (Date.gettime () + expireshours * 1000); The unit is millisecond cookiestring = cookiestring + "; expires=" + date.togmtstring ();} document.cookie = cookiestring;} Gets the value of the cookie by name Function getcookievalue (name) {var strcookie = document.cookie;var arrcookie = strcookie.split ("; ");for (var i = 0; i <& NBsp;arrcookie.length; i++) {var arr = arrcookie[i].split ("=");if (arr[0] == name) {return unescape (arr[1]); else {continue;};};}
JS write online exam countdown, cookie prevents refresh