JS write online exam countdown, cookie prevents refresh

Source: Internet
Author: User

$ (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  &LT;&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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.