JQuery + Cookie-based online examination countdown to prevent refresh-jquery-js tutorial

Source: Internet
Author: User
This article mainly introduces the method and example of online examination countdown to prevent refresh Based on jQuery + Cookie, if you need it, you can refer to the online examination countdown Based on jQuery + Cookie to prevent refresh.

$ (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 <arrCookie. length; I ++) {var arr = arrCookie [I]. split ("="); if (arr [0] = "$ {examinee. examineeId} ") {return true ;}; return false ;}// start the countdown function settime (remain Time) {var _ time = getCookieValue ("871d31bacfd4451484c5f70f8860c2a9"); var _ countdown = parseInt (getCookieValue ("$ {examinee. examineeId} ")/1000; if (_ countdown <= 0) {alert (" the exam time is up! "); EndExam ();} else {var _ second = _ countdown % 60; var _ minute = parseInt (_ countdown/60) % 60; var _ hour = parseInt (_ countdown/60)/60); if (_ hour <10) _ hour = "0" + _ hour. toString (); if (_ second <10) _ second = "0" + _ second. toString (); if (_ minute <10) _ minute = "0" + _ minute. toString (); remainTime.html (_ hour + ":" + _ minute + ":" + _ second); _ countdown --; editCookie ("$ {examin Ee. examineeId} ", _ countdown * 1000, _ countdown * 1000);} // setTimeout (function () {settime (remainTime) every 1000 milliseconds );}, 1000) ;}; // Add cookie function addCookie (name, value, expiresHours) {var cookieString = name + "=" + escape (value); // escape () the function can encode the string so that the string can be read on all computers. // Determine whether to set the expiration time. 0 indicates that the browser is disabled if (expiresHours> 0) {var date = new Date (); date. setTime (date. getTime () + expiresHours * 1000); cookieString = cookieString + "; expires =" + date. toUTCString ();} document. cookie = cookieString;} // modify the 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); // The unit is milliseconds cookieString = cookieString + "; expires =" + date. toGMTString ();} document. cookie = cookieString;} // obtain the cookie value based on the name 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 all the content of this article. I hope you will like it.

Related Article

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.