【问题标题】:Django - count up timerDjango - 倒计时
【发布时间】:2019-05-18 04:41:26
【问题描述】:

嘿,我想实现一个计时器,如果我转到这个模板就会启动:

{% block content %}


 <h3>C-Test</h3>

  <p>In the following text, some of the word endings have been replaced by a gap. The gap is approximately half of the word, e.g. if you see 3 letters, you need to add another 3-4 letters to complete the word. Try your best.</p>

  <form action="results" id=results method="POST">
  <input type="hidden" name="cTestFormat" value="{{ text }}">

    <div class="ctest">
        {% csrf_token %}
        {{  forms }}{{ ende }}
    </div>

    <div class="command">
      <button type="submit" name="ctest_submit">Submit solution</button>
    </div>
  </form>


{% endblock %}

并在我单击提交解决方案按钮时结束。

我希望将其保存到POST 请求中,以便我可以在results.html 中返回时间。

这是我的results.html

{% block content %}


<h3>C-Test</h3>
  {% csrf_token %}
  <p>You got {{ richtige }} right!!!!!!</p>
  <p>But {{ falsche }} wrong :(</p>

  <p> {{ testresult|safe }}</p>


{% endblock %}

我读到您需要一些脚本语言来编写计时器,但我对此没有任何经验。 django 有没有其他方法可以做到这一点,还是我需要类似 javascript 的东西?

【问题讨论】:

    标签: javascript html django timer django-templates


    【解决方案1】:

    这是一个使用 JQuery 的示例

    <script type="text/javascript>
        var sec = 0;
        function pad ( val ) { return val > 9 ? val : "0" + val; }
        setInterval( function(){
            $("#seconds").html(pad(++sec%60));
            $("#minutes").html(pad(parseInt(sec/60,10)));
        }, 1000);
    </script>
    

    HTML:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <span id="minutes"></span>:<span id="seconds"></span>
    

    【讨论】:

    • 非常感谢您的回答。我可以在我的模板中使用此代码还是需要先下载一些要求?
    猜你喜欢
    • 2015-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-20
    • 2021-03-22
    • 2020-09-04
    相关资源
    最近更新 更多