简体   繁体   中英

Flask - how to dynamically set 'checked' property to an input checkbox

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM