Javascript 如何使用select的值创建if?
您好,我有以下代码:Javascript 如何使用select的值创建if?,javascript,python,html,django,Javascript,Python,Html,Django,您好,我有以下代码: <select name="test1" class="form-control"> <option value=""></option> {% for test in tests %} <option value="{{ test.id }}"&g
<select name="test1" class="form-control">
<option value=""></option>
{% for test in tests %}
<option value="{{ test.id }}">{{ test.name }}</option>
{% endfor %}
</select>
我如何才能做到这一点?看看这种方法是否有帮助
<select name="test1" class="form-control">
<option value=""></option>
{% for test in tests %}
<option value="{{ test.id }}">{{ test.name }}</option>
{% if test.id %}
#show what you want..
{% empty %} <<<<======
#if empty do this...
{% endif %}
{% endfor %}
</select>
现在在templates/template.html中
{% for i in data %}
<div class="row">
{{ i }}
</div>
{% empty %}
<h4>There is nothing in this list</h4>
{% endfor %}
{%for i in data%}
{{i}
{%empty%}
这张单子上什么也没有
{%endfor%}
您可以更好地查看此链接:
看看这种方法是否有帮助
<select name="test1" class="form-control">
<option value=""></option>
{% for test in tests %}
<option value="{{ test.id }}">{{ test.name }}</option>
{% if test.id %}
#show what you want..
{% empty %} <<<<======
#if empty do this...
{% endif %}
{% endfor %}
</select>
现在在templates/template.html中
{% for i in data %}
<div class="row">
{{ i }}
</div>
{% empty %}
<h4>There is nothing in this list</h4>
{% endfor %}
{%for i in data%}
{{i}
{%empty%}
这张单子上什么也没有
{%endfor%}
您可以更好地查看此链接:
也许你需要这个。否它不起作用:/test.id不是None%}请尝试使用
{%。否它不起作用:/test.id不是None%时,尝试使用{%