测验上的计时器

时间:2014-02-12 10:34:20

标签: drupal drupal-7

我有一个测验,我必须在一个用户参加测验时显示一个计数器,但我不知道该怎么做,因为我看到了jquery_countdown模块,但它只适用于倒计时。 谁知道怎么做?

提前致谢。

1 个答案:

答案 0 :(得分:0)

我做了这个解决方案:

Tiempo transcurrido: <span id="minutes">00</span>:<span id="seconds">00</span>
<script type="text/javascript">
    var minutesLabel = document.getElementById("minutes");
    var secondsLabel = document.getElementById("seconds");
    var totalSeconds = localStorage.getItem("totalSeconds") || 0;
    setInterval(setTime, 1000);

    function setTime()
    {
        ++totalSeconds;
        localStorage.setItem("totalSeconds", totalSeconds);
        secondsLabel.innerHTML = pad(totalSeconds%60);
        minutesLabel.innerHTML = pad(parseInt(totalSeconds/60));
    }

    function pad(val)
    {
        var valString = val + "";
        if(valString.length < 2)
        {
            return "0" + valString;
        }
        else
        {
            return valString;
        }
    }
</script>

我使用localstorage因为我需要那个计数器保持他的状态。当我进入开始页面测验时,我重置了这个计数器。