【发布时间】:2021-09-04 06:09:49
【问题描述】:
我正在创建一个应用程序,将多个测验的答案显示在一个页面上。
为此,我有一个for 循环,它循环遍历每个循环,并在该循环中使用if 标签将正确答案涂成绿色。但是,所有测验都得到相同的答案颜色,因为 css 样式不会停留在每个 for 循环之间。
我怎样才能阻止这种情况?
{% for quiz in Quizes %}
<div class="question-Card">
<p id="a"> A:{{choice1}}
<p id="b"> A:{{choice2}}
<p id="c"> A:{{choice3}}
<p id="d"> A:{{choice4}}
{% if quiz.answer == 'a' %}
<style>
#a {
color: green;
}
</style>
{% endif %}
**this then continues for the other choices
but the code isn't the issue, so I will save you the read**
</div>
{% endfor %}
问题是,如果要“阅读”的最后一个测验是 c 色,那么它们都是 c 色的,并且它不会单独完成每个测验,请帮助
【问题讨论】:
-
问题是下一个问题可以有
'a'作为答案,并且由于id都相同,这意味着样式也将应用于下一个条目的样式。
标签: javascript html css django