我找到了一个主题,讨论了如何根据行值更改html表的行颜色。在我的例子中,这个解决方案不起作用。我想根据与表行相关联的类的值来更改每行的颜色。例如:如果的类是红色的" red“,则将行设置为红色,但为其他类保留默认颜色。我能做些什么来让它工作呢?
<table class="table table-striped" id="mytable">
<thead>
<tr>
<th>Nom du cours</th>
<th>Matière</th>
<th>Date d'enregistrement</th>
<th>Date d'apprentissage</th>
<th>Nombre d'études</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
while($cour = $load->fetch()){
if(condition){
$data = "red";
}else{
$data = "none";
}
echo '
<tr id = "cours_row" class='.$data.'>
<td class="nom_cours">'.$cour['nom_cours'].'</td>
<td class="nom_matiere">'.$cour['nom_matiere'].'</td>
<td class="first_append">'.$cour['first_append'].'</td>
<td class="next_append">'.$formater -> format(strtotime($cour['next_append'])).'</td>
<td class="number_append">'.$cour['number_append'].'</td>
<td class="actions">Actions</td>
</tr>
';
}
?>
</tbody>
</table>发布于 2018-08-29 01:54:52
决定在PHP中分配什么:
$data = condition?"red":"natural";CSS:
.red {
background-color: red;
}
.natural {
background-color: inherit;
}https://stackoverflow.com/questions/52061485
复制相似问题