【发布时间】:2022-01-18 10:17:07
【问题描述】:
我在 CSS 中定义了 3 种颜色。在 HTML 中,我有表格,我希望单元格的背景颜色根据 3 个条件进行更改:
if cell contains the text 'True' - color green
if cell contains the text 'False' - color red
if the cell contains the text 'None' - color yellow
我的CSS:
.color-green {
background-color: green;
color: black;
}
.color-yellow {
background-color: orange;
color: black;
}
.color-red {
background-color: red;
color: black;
}
我的html:
<td ng-class = "{'color-yellow':dict.status='True','color-red':dict.status=='false'}">{{ dict.status}}</td>
我首先尝试使用 2 种颜色,但这只是将我的单元格更改为带有红色背景的 True。 我很长时间没有接触过 html,但我记得这种方法适用于数字。 尝试谷歌但没有那么幸运:(
有什么方法可以用 3 种颜色做我想做的事吗?
【问题讨论】:
-
这是 AngularJS 还是 Angular?请添加正确的标签。
-
它是有角度的。我会添加
-
你有
dict.status='True'这不是一个条件,而是赋值——你将 dict.status 设置为“真”。使用 == 并检查您是否希望它读取 'true' 或 'True'