How can I dynamically add checked
property to my input checkbox, assuming my object
has an active
property?
{% for object in objects %}
<li>
<input type="checkbox" id="id_{{object.id}}" name="checkbox" value={{object.id}}>
</li>
{% endfor %}
Adding checked="{{object.active}}"
did not work.
要将checked
属性添加到您的复选框输入元素,您可以像这样动态添加它:
<input type="checkbox" id="id_{{object.id}}" name="checkbox" value={{object.id}} {{'checked' if object.active else ''}}>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.