首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有类的Dynatable行颜色

具有类的Dynatable行颜色
EN

Stack Overflow用户
提问于 2018-08-28 23:27:02
回答 1查看 135关注 0票数 0

我找到了一个主题,讨论了如何根据行值更改html表的行颜色。在我的例子中,这个解决方案不起作用。我想根据与表行相关联的类的值来更改每行的颜色。例如:如果的类是红色的" red“,则将行设置为红色,但为其他类保留默认颜色。我能做些什么来让它工作呢?

代码语言:javascript
复制
    <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>
EN

回答 1

Stack Overflow用户

发布于 2018-08-29 01:54:52

决定在PHP中分配什么:

代码语言:javascript
复制
$data = condition?"red":"natural";

CSS:

代码语言:javascript
复制
.red {
    background-color: red;
}
.natural {
    background-color: inherit;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52061485

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档