html - 如何根据显示的值悬挂行的背景颜色?
问题描述
我需要根据显示的值更改整个表格行的背景颜色。如果值notas
- < 38 然后是红色,
- 如果是 ==38 那么蓝色和
- 其余的都是绿色的。
我只需要使用 CSS 来完成。我尝试的所有解决方案都会删除显示的信息。
<table class="wp-table" id="posts">
<tr>
<th>ID</th>
<th>Nota Original </th>
<th>Nota Redondeada</th>
</tr>
</table>
<script>
const notas = [38,43,99,97,29,29,0, 100,40,41,42,43, 44,45,37,39, ];
const notasid = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
let notasr = notas.map((num) => {
const remainder = num % 5;
if (num< 38) {
return num;
} else if (remainder >= 3) {
num+=5-remainder
};
return num;
})
var t = "";
for (var i = 0; i < notas.length; i++){
var tr = "<tr>";
tr += "<td>"+notasid[i]+"</td>";
tr += "<td>"+notas[i]+"</td>";
tr += "<td>"+notasr[i]+"</td>";
tr += "</tr>";
t += tr;
}
document.getElementById("posts").innerHTML += t;
</script>
解决方案
在这种情况下,为所有 < 38 的项目添加红色类并通过 CSS 将它们变为红色将是更多问题。您不能通过 CSS 覆盖值范围。
推荐阅读
- ios - 手动如何在Objective C中的ARC下释放对象(NSString / NSMutableString ,..)
- javascript - 使用参数依赖于子组件的函数更新父组件状态
- ios - Swift:如何对 tableView 中的单元格进行排序?
- python - 从另一个脚本调用时如何使用 ArgumentParser 将参数传递给脚本
- python - 表单中没有邮件默认值
- typescript - 如何强制 TypeScript 确保所有 const、let 和 var 变量必须用它们的类型声明
- android - 无法从 Android 上的特征读取数据,但能够在 iOS Flutter Blue 上读取
- c++ - 使用 range-v3 构建无限范围
- python - 如何在 python pyvista 中读取 dem 文件
- c++ - c ++:将父类转换为子类并调用子类的函数