duanjiao2978 2016-09-18 14:12
浏览 91

倒计时器在每页重置

i have an exam system in php on which i have set a countdown timer with the help of javascript. the questions are displayed one by one on the page and the timer reset to the initial position when the next question comes also the page refreshes itself. I want to set the timer on the decreasing state so is should not start again and again to the initial time. the code is the following i have written for the timer. please anyone help me to sort it out.

<div id="test_time">
    <script language="javascript" type="text/javascript">
        var min = 10;
        var sec = 0;
        var timer;
        var timeon = 0;
        function ActivateTimer() {
            if (!timeon) {
                timeon = 1;
                Timer();
            }
        }
        function Timer() {

            var _time = "Time Left : Minutes: " + min + " Seconds: " + sec;
            document.getElementById("test_time").innerHTML =_time;
            if (_time != "Time Left : Minutes: 0 Seconds: 0") {
                if (sec == 0) {
                    min = min - 1;
                    sec = 59;
                } else {
                    sec = sec - 1;
                }
                timer = setTimeout("Timer()", 1000);
            }
            else {
                alert('Test Time Over.. Click Ok to get Results.');
             window.location = "result.php";

            }
        }
    </script>
    </div>
  • 写回答

2条回答 默认 最新

  • dsf5632 2016-09-18 14:18
    关注

    First you must understand the concept of Jquery while working with the countdown timer and Quiz like PHP project.

    You have to follow the following process in the System:

    1. You have to load the question in AJAX.
    2. You must have the div which loads the timer at the page load after the login is being done.
    3. The timer div must not be loaded since the jquery will be keep loading if the page reloads again.
    4. Only once the page has to be loaded that is after the login is done and after that the page should not be loaded and it has to changed inly with the help of AJAX.

    Since if the question is loaded over the AJAX only the question div alone will be loaded and that to with AJAX and all the other part of the page will remain the same and you can maintain the timer in a correct manner.

    Hope so you might be clear with the Explanations.

    Happy Coding :)

    评论

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集