为在线考试创建javascript计时器 [英] Create javascript timer for online examination

查看:78
本文介绍了为在线考试创建javascript计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个php应用程序。但我无法创建会话可用于所有问题的计时器。我已经看到了一些代码,但是在刷新页面时,它又开始重新计算



我尝试了什么:



i已经做了很多关于做什么的研究,现在一切看起来都是流产的。一旦刷新页面,javascript将再次开始计数

i am developing a php application. but i cannot create a timer that the session can use for all the questions. i have seen some code but on refresh of the page, it starts counting again

What I have tried:

i have pretty done alot of research on what to do, for now everything seem abortive. the javascript will start counting again once the page is refreshed

推荐答案

javascript中的'setTimeout'方法怎么样?你试过一次吗?

结账以下倒数计时器代码片段看看它是否适合你

what about 'setTimeout' method in javascript ? have you tried once ?
checkout below count down timer code snippet see if it works for you
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language ="javascript" >
        var tim;
       
        var min = 20;
        var sec = 60;
        var f = new Date();
        function f1() {
            f2();
            document.getElementById("starttime").innerHTML = "Your started your Exam at " + f.getHours() + ":" + f.getMinutes();
             
          
        }
        function f2() {
            if (parseInt(sec) > 0) {
                sec = parseInt(sec) - 1;
                document.getElementById("showtime").innerHTML = "Your Left Time  is :"+min+" Minutes ," + sec+" Seconds";
                tim = setTimeout("f2()", 1000);
            }
            else {
                if (parseInt(sec) == 0) {
                    min = parseInt(min) - 1;
                    if (parseInt(min) == 0) {
                        clearTimeout(tim);
                        location.href = "default5.aspx";
                    }
                    else {
                        sec = 60;
                        document.getElementById("showtime").innerHTML = "Your Left Time  is :" + min + " Minutes ," + sec + " Seconds";
                        tim = setTimeout("f2()", 1000);
                    }
                }
               
            }
        }
    </script>
</head>
<body onload="f1()" >
    <form id="form1" runat="server">
    <div>
      <table width="100%" align="center">
        <tr>
          <td colspan="2">
            <h2>This is head part for showing timer and all other details</h2>
          </td>
        </tr>
        <tr>
          <td>
            <div id="starttime"></div>
 
            <div id="endtime"></div>
 
            <div id="showtime"></div>
          </td>
        </tr>
        <tr>
          <td>
          </td>
        </tr>
      </table>
    </div>
    </form>
</body>
</html>


这篇关于为在线考试创建javascript计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆