gpt4 book ai didi

python - Django 复选框只想选中第一个框

转载 作者:行者123 更新时间:2023-12-01 06:12:43 25 4
gpt4 key购买 nike

另一个复选框问题。我的列表中有项目。每个项目都有一个复选框。我想要做的是勾选列表中的FIRST项目的复选框。没错,由于 checked="checked",它已经勾选了所有复选框。

{% for item in items %}
<tr class="items_table_row">
<td><input type="checkbox" name="{{item.pk}}" value="{{item.pk}}" checked="checked"></td>
<td>{{item.tiptop_id}}</td><td>{{item.alternative_id}}</td><td>{{item.title}}</td><td>{{item.type}}</td><td>{{item.format}}</td>
<td><span id="{{item.pk}}" name="type">{{item.itemstatushistory_set.latest}}</span></td><td>{{item.itemstatushistory_set.latest.date.date|date:"d M Y"}}</td>
<td><a href="{% url tiptop.views.edit_item item.client.pk item.pk %}" onclick="return showAddAnotherPopup(this);">Edit</a></td>
</tr>
{% endfor %}

最佳答案

您可以将选中的属性添加到第二个项目,如下所示:

{% ifequal forloop.counter 2 %} checked="checked"{% endifequal %}

默认的forloop.counter是1索引的,或者您可以专门使用0索引的计数器:

forloop.counter0

关于python - Django 复选框只想选中第一个框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4864481/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com