This article mainly introduces the implementation of Jquery+cookie based on the online test to prevent the countdown method and examples, the need for small partners can refer to the
Online exam countdown to prevent refresh based on Jquery+cookie implementation
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5 86 87 |
$ (function () {var _minute = parseint ("${exampaper.papertime}"); var _expireshours = _minute * 1000; if (!has Setcookie ()) {Addcookie ("${examinee.examineeid}", _expireshours, _expireshours);} settime ($ ("#remainTime"); }); function Hassetcookie () {var strcookie = Document.cookie; var Arrcookie = Strcookie.split (";"); for (var i = 0; i < AR Rcookie.length; i++) {var arr = arrcookie[i].split ("="); if (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 ("Time to test!") "); Endexam (); else {var _second = _countdown%; var _minute = parseint (_countdown/60)%; var _hour = parseint (parseint (_count DOWN/60)/60); if (_hour <) _hour = "0" + _hour.tostring (); if (_second <) _second = "0" + _second.tostring (); if (_minute &Lt _minute = "0" + _minute.tostring (); remaintime.html (_hour + ":" + _minute + ":" + _second); _countdown--; Editcookie ("${examinee.examineeid}", _countdown * 1000, _countdown * 1000); settimeout (function () {settime (remaintime);}, 1000) per 1000 milliseconds; }; //Add cookie function Addcookie (name, value, expireshours) {var cookiestring = name + "=" + escape (value);//escape The () function encodes the string so that it can be read on all computers. Determines whether the expiration time is set, 0 means the invalidation if (expireshours > 0) {var date = new Date () for closing the browser () Date.settime (Date.gettime () + expireshours * 10 00); cookiestring = cookiestring + "; expires=" + date.toutcstring (); } document.cookie = cookiestring; //Modify cookie Value function Editcookie (name, value, expireshours) {var cookiestring = name + ' = ' + escape (value); if ( Expireshours > 0) {var date = new Date (); Date.settime (Date.gettime () + expireshours * 1000);//unit is milliseconds cookiestring = C Ookiestring + "expires=" + date.togmtstring (); } document.cookie = cookiestring; //Get COO by nameKie value function Getcookievalue (name) {var strcookie = Document.cookie; var Arrcookie = Strcookie.split (";"); for (var i = 0; i < arrcookie.length; i++) {var arr = arrcookie[i].split ("="), if (arr[0] = = name) {return unescape (arr[1)), break;} else {continue;};}; } |
The above is the entire contents of this article, I hope you can enjoy.