Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用select的值创建if?_Javascript_Python_Html_Django - Fatal编程技术网

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%时,尝试使用
{%