比较来自世界各地的卖家的域名和 IT 服务价格

如何使用 {{key}} 的 django 在 javacript

Javascript 无法使用{{键}找到标识符元素

如何在脚本中访问{{键}?

脚本


window.onload = jQuery/function /$/ {
var duration = document.getElementById/"#timerseconds{{key}}"/.value;
duration = 10800 - duration;
display = $/"#counter{{key}}"/;
startTimer/duration, display/;
}/;


HTML / DJANGO


{% for key, value in list_cooking.items %}

<li class="list-group-item">
<p>{{key}}</p>
<br/>
<p>Seconds:</p><p id="counter{{key}}">00</p>
<input id="timerseconds{{key}}" type="hidden" value="{{value}}"/>
</li>


安慰


jQuery.Deferred exception: Cannot read property 'value' of null TypeError: Cannot read property 'value' of null

jquery.min.js:2 Uncaught TypeError: Cannot read property 'value' of null
at HTMLDocument.<anonymous> /main.js:78/


渲染 HTML


<li class="list-group-item">
<p>Beef</p>
<br/>
<p>Seconds:</p>
<p id="#counterBeef">00</p>
<input id="timersecondsBeef" type="hidden" value="5417"/>
</li>


VIEW


time_since = AddCooking.objects.raw/"select * from heatcook_addcooking where time_start &gt; now// - interval '180 minutes'"/

for item in time_since:
list_cooking[item.foodfk.name] = /int//time_now - item.time_start/.total_seconds////


决定:

在里面 for loop


{% for key, value in list_cooking.items %}
<script>Script here</script>
<li class="list-group-item">
<p>{{key}}</p>
<br/>
<p>Seconds:</p><p id="counter{{key}}">00</p>
<input id="timerseconds{{key}}" type="hidden" value="{{value}}"/>
</li>


</anonymous>
已邀请:

君笑尘

赞同来自:

您还必须重复该代码。 JavaScript 在模板中:


{% for key, value in list_cooking.items %}
<li class="list-group-item">
<p>{{key}}</p>
<br/>
<p>Seconds:</p><p id="counter{{key}}">00</p>
<input id="timerseconds{{key}}" type="hidden" value="{{value}}"/>
</li>
<script type="text/javascript">
window.onload = jQuery/function /$/ {
var duration = $/"#timerseconds{{key}}"/.val//;
duration = 10800 - duration;
display = $/"#counter{{key}}"/;
startTimer/duration, display/;
}/;
</script>
{% endfor %}

要回复问题请先登录注册