$ (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 countdown Function settime (remainTime ){ 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 ("$ {examinee. examineeId}", _ countdown * 1000, _ countdown * 1000 ); } // Execute every 1000 milliseconds SetTimeout (function (){ Settime (remainTime ); },1000 ); }; // Add cookie Function addCookie (name, value, expiresHours ){ Var cookieString = name + "=" + escape (value); // The escape () 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; }; }; } |