【发布时间】:2015-06-13 04:56:00
【问题描述】:
我有一个 html 页面,我在其中动态显示属性列表。接下来,我统计每个 div 中显示的属性数量。
<script type="text/javascript">
var numItems = $('.countdiv').length;
</script>
countdiv 是每个属性的类名。现在在我的 html 页面中,我有一个变量 properties_count,其中包含从我的数据库中获取的总属性的计数。
我想在if 语句中比较numItems 和properties_count,如下所示:
{% if(numItems!=properties_count) %}
# some function to load more properties
但是比较不起作用。如何在 html 中使用 numItems(javascript 变量)?
【问题讨论】:
-
那是因为 numItems 是一个 javascript 变量
-
是的,我知道,这就是为什么我在标题中提到,如何在 html 中使用 javascript 变量。你能解释一下如何在 html 中使用 numItems 变量吗?
-
Jquery 模板可以帮助你。
-
Jinja 在 javascript(在浏览器中)之前执行(在服务器上),所以你想要的无法完成。你应该使用 Yuv 的方法。
标签: javascript jquery python html jinja2