There will inevitably be a countdown prompt in the examination system. The first thing we think of is to use the settimeout of js.
However, if the page is refreshed, a countdown is triggered. Here is my solution:
1. use settimeout to trigger every second
2. Use cookies to read the remaining time in cookies
The following is the implementation code:
Js section:
1 <script language = "javascript" type = "text/javascript">
2 function GetCookieByName (name ){
3 // obtain the cookie string
4 var strCookie = document. cookie;
5 // cut multiple cookies into multiple name/value pairs
6 var arrCookie = strCookie. split (";");
7 var userId;
8 // traverse the cookie array to process each cookie pair
9 for (var I = 0; I <arrCookie. length; I ++ ){
10 var arr = arrCookie [I]. split ("= ");
11 // find the cookie named name and return its value
12 if (name = arr [0]) {
13 userId = arr [1];
14 break;
15}
16}
17 return userId;
18}
19 function Change (m, s ){
20 s = s-1;
21 if (s <0 ){
22 s = 60 + s;
23 m = m-1;
24}
25 if (m = 10 & s = 0 ){
26 alert ("there are 10 minutes before the answer is over. Please finish the question as soon as possible! ");
27}
28 document. getElementById ("divtime"). innerHTML = m + "Minute" + s + "second ";
29 document. cookie = "m =" + m;
30 document. cookie = "s =" + s;
31 setTimeout (function (){
32 Change (m, s );
33}, 1000 );
34}
35 window. onload = function (){
36 // SetCookie (20, 20 );
37 var m = GetCookieByName ("m ");
38 var s = GetCookieByName ("s ");
39 Change (m, s );
40
41}
42 </script>
. Net Background:
Set cookies in background code
Response. Cookies ["m"]. Value = strs [0];
Response. Cookies ["s"]. Value = strs [1];
From wlitsoft