如果在打开当前页面之前在页面上选中了复选框,我会尝试打开带有复选框的HTML页面。我目前的代码如下:
{% if job.activism %}
checkbox??????
{% endif %}
<br><input type="checkbox" name="activism" value="Yes">Activism & advocacy
我的后端是django,我的前端是HTML。 感谢
答案 0 :(得分:0)
如果默认情况下显示所有复选框,并且仅在条件返回true时选中,请尝试以下操作:
<input type="checkbox" name="activism" value="Yes" {% if job.activism %}checked{% endif %}>Activism & advocacy
答案 1 :(得分:0)
添加“checked”属性,例如:
<br><input type="checkbox" name="activism" value="Yes" checked>Activism & advocacy
来自https://www.w3schools.com/tags/att_input_checked.asp
<form action="/action_page.php">
<input type="checkbox" name="vehicle" value="Bike"> I have a bike<br>
<input type="checkbox" name="vehicle" value="Car" checked> I have a car<br>
<input type="submit" value="Submit">
</form>