1 回答
TA贡献1909条经验 获得超7个赞
您可以简单且最简单的方法是使用Javascript querySelectorAll方法获取td's
表中的所有内容并检查它们的textContentif
并使用条件应用颜色
如果条件matches
与severity
水平那么你可以使用style
任何background
你喜欢使用的。
现场工作示例:
let getTds = document.querySelectorAll('table td')
getTds.forEach(function(row) {
//Low
if (row.textContent == 'Low') {
row.style.background = 'green'
}
//Medium
if (row.textContent == 'Medium') {
row.style.background = 'yellow'
}
})
table {
width: 750px;
border-collapse: collapse;
margin: 20px auto;
}
tr:nth-of-type(even) {
background: #eee;
}
tr:hover {
background-color: #f5f5f5;
}
th {
background: #1489b8;
color: white;
font-weight: default;
}
td,
th {
padding: 10px;
border: 3px solid #ccc;
text-align: center;
font-size: 15px;
}
h3,
p {
text-align: center;
}
<head>
<h3>Hi User,</h3>
<p>An alert is created. Following are the details.</p>
</head>
<table style="width:100%">
<thead>
<tr>
<th> Description</th>
<td>working</td>
</tr>
<tr>
<th>Parameter</th>
<td>Shutdown</td>
</tr>
<tr>
<th>Machine </th>
<td>ABC</td>
</tr>
<tr>
<th> Type</th>
<td>Sensor Machine</td>
</tr>
<tr>
<th> Severity</th>
<td>Low</td>
</tr>
</thead>
<thead>
<tr>
<th> Description</th>
<td>working</td>
</tr>
<tr>
<th>Parameter</th>
<td>Shutdown</td>
</tr>
<tr>
<th>Machine </th>
<td>ABC</td>
</tr>
<tr>
<th> Type</th>
<td>Sensor Machine</td>
</tr>
<tr>
<th> Severity</th>
<td>Medium</td>
</tr>
</thead>
</table>
添加回答
举报