【发布时间】:2019-01-25 19:13:59
【问题描述】:
我希望根据 th:if 条件更改表格行的背景颜色。
例如:如果预期 != 实际,则 bg = 红色。反之亦然,bg = 绿色。
对于我的示例,我目前有三列——评估类型、预期和实际。评估类型确定预期值和实际值。当前跨度th:style 正确突出显示各个单元格,但我希望根据评估将整个<tr> 突出显示为红色或绿色。
当前代码:
<thead>
<th>Eval Type </th>
<th>Expected </th>
<th>Actual </th>
</thead>
<tbody>
<tr>
<td>
<span th:if="${example.getEvaluationType()} == '1'" th:text="${example.getExpectedcount()}"
th:style="${example.getActualcount()} == ${example.getExpectedcount()} ? 'background: green' : 'background: red'"></span>
<span th:if="${example.getEvaluationType()} == '2'" th:text="${example.getExpectedmb()}"
th:style="${example.getActualmb()} == ${example.getExpectedmb()} ? 'background: green' : 'background: red'"></span>
<span th:if="${example.getEvaluationType()} == '3'" th:text="${example.getExpectedminutes()}"
th:style="${example.getActualminutes()} == ${example.getExpectedminutes()} ? 'background: green' : 'background: red'" ></span>
</td>
</tr>
</tbody>
感谢任何有关问题的帮助或线索,因为我没有找到任何问题。 谢谢!
【问题讨论】:
标签: spring spring-mvc thymeleaf