Design Scheme of no new countdown in Online Examination System

Source: Internet
Author: User

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
 

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.