[英]Why is UL making a bullet?
我有以下HTML/Jinja2
代碼:
<div class="controls" id="pos">{% if context.job_history %} {% for k in context.job_history %} {% for v in k %} {% if v == "job_title" %}
<div class='job'>
<h3>{{ k[v] }}</h3>
<input name='job_title[]' type='hidden' class='form-control' value='{{ k[v] }}' />
<ul class='control-group list-inline'>{% endif %} {% if v == "from_" %}
<li>
<input name='from[]' type='hidden' class='form-control' style='width:130px' value='{{ k[v]|replace("00:00:00", "")|replace("-", "/") }}' />{{ k[v]|replace("00:00:00", "")|replace("-", "/") }} –</li>{% endif %} {% if v == "current_position" %}
<li>{{ k[v]==True and "Present" or "" }}</li>
</ul>{% elif v == "to_" %}
<li>
<input name='to[]' type='hidden' style='width:130px' class='form-control' value='{{ k[v]|replace("00:00:00", "")|replace("-", "/") }}' />{{ k[v]|replace("00:00:00", "")|replace("-", "/") }}</li>
</ul>{% endif %} {% if v == "industries" %}
<ul class="nav nav-pills">
<div align='center'>{% for industry in k[v] %}
<li> <a>{{ industry }}</a>
</li>{% endfor %}
<input type="hidden" value="{{ k[v]|join(" , ") }}" class="form-control" name="industries[]">
</div>
</ul>{% endif %} {% endfor %}
<br /> <a href='#' class='delete btn btn-danger btn-xs'>Remove</a>
</div>{% endfor %} {% endif %}</div>
上面的代碼生成了這個輸出:
當我查看此代碼段的來源時,它顯示了一個空的列表元素:
<li> </li>
我看不到它為什么這樣做,我試圖將</ul>
標記移入if語句內外,就像上面的代碼一樣,我試圖在結束if語句之前放置</ul>
標記:
</ul>
{% endif %}
我想念什么? 為什么會這樣?
更新:
因此,我對代碼做了一些更改:
{% if context.job_history %}
{% for k in context.job_history %}
{% for v in k %}
<div class='job'>
{% if v == "job_title" %}
<h3>{{ k[v] }}</h3>
<input name='job_title[]' type='hidden' class='form-control' value='{{ k[v] }}' />
{% endif %}
{% if v == "from_" %}
<input name='from[]' type='hidden' class='form-control' style='width:130px' value='{{ k[v]|replace("00:00:00", "")|replace("-", "/") }}' />
{% endif %}
{% if v == "current_position" %}
<input name='present[]' type='hidden' class='form-control' value='{{ k[v] }}' />
{% endif %}
{% if v == "to_" %}
<input name='to[]' type='hidden' style='width:130px' class='form-control' value='{{ k[v]|replace("00:00:00", "")|replace("-", "/") }}' />
{% endif %}
{% if v == "industries" %}
<input type="hidden" value="{{ k[v]|join(",") }}" class="form-control" name="industries[]">
{% endif %}
{% if v == "from_" %}
<ul class='control-group list-inline'>
<li>
{{ k[v]|replace("00:00:00", "")|replace("-", "/") }}
–
</li>
{% if v == "current_position" %}
<li>
{{ k[v]==True and "Present" or "" }}
</li>
{% elif v == "to_" %}
<li>
{{ k[v]|replace("00:00:00", "")|replace("-", "/") }}
</li>
{% endif %}
</ul>
{% endif %}
{% if v == "industries" %}
<ul class="nav nav-pills">
{% for industry in k[v] %}
<li style="display: inline-block">
<a>{{ industry }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
<br />
<a href='#' class='delete btn btn-danger btn-xs'>Remove</a>
</div>
{% endfor %}
{% endif %}
我發現是我的if-statement
引起了問題。 流浪子彈不再存在。
使用標記驗證器 (在生成的HTML而不是模板上)。
您不能將div
元素作為ul
的子級或li
的父級。 由於錯誤恢復,很可能導致生成額外的列表項。
您還似乎將ul
和li
元素作為同級,這在HTML中也是不可能的。
ul
不平衡 /ul
之后有一個li
嗎?
</ul>{% elif v == "to_" %}
<li>
<input name='to[]' type='hidden' style='width:130px' class='form-control' value='{{ k[v]|replace("00:00:00", "")|replace("-", "/") }}' />{{ k[v]|replace("00:00:00", "")|replace("-", "/") }}</li>
</ul>{% endif %} {% if v == "industries" %}
另外, div
在ul
里面嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.