2016-06-21 82 views
0

当条件满足时,如何更改表中整行的颜色?当条件满足时,更改表中整行的颜色?

例如,返回FAILURE?使整行成为红色。

<tr> <!-- Disk Space Available --> 
       <td class="tg-yw4l">ld</td> 
       <td class="tg-yw4l"> 
       <?php 
        if ($ld_status == 0) { 
         echo 'SUCCESS'; 
        } else if ($ld_status == 1) { 
         echo 'WARNING'; 
        } else { 
         echo 'FAILURE'; 
        } 
       ?> 
       </td> 

+0

使用''标签的bgcolor属性。 –

+1

@DanBracuk [甚至W3Schools](http://www.w3schools.com/tags/att_tr_bgcolor.asp)(不完全知道在曲线之前)谨慎使用'bgcolor'属性。 –

回答

3

您可以生成类PHP的TR,那么在CSS中你可以改变每个类的风格。

CSS

.success{ 
    background-color: green; 
    } 

.warning{ 
    background-color: yellow; 
    } 

.failure{ 
    background-color: red; 
    } 

HTML

<tr class=" <?php 
        if ($ld_status == 0) { 
         echo 'success'; 
        } else if ($ld_status == 1) { 
         echo 'warning'; 
        } else { 
         echo 'failure'; 
        } 
       ?>"> 

       <td class="tg-yw4l">ld</td> 
       <td class="tg-yw4l"> 
       <?php 
        if ($ld_status == 0) { 
         echo 'SUCCESS'; 
        } else if ($ld_status == 1) { 
         echo 'WARNING'; 
        } else { 
         echo 'FAILURE'; 
        } 
       ?> 
       </td> 
0

试试这将是工作的合适你的病情

<html> 
    <body> 
    <?php $ld_status=2; ?> 
    <table border="1"> 
    <tr style="background:<?php if($ld_status == 0) { echo 'green'; } else if ($ld_status == 1){ echo 'yellow'; } else { echo 'red';}?>;" > <!-- Disk Space Available --> 
        <td class="tg-yw4l">ld</td> 
        <td class="tg-yw4l"> 
        <?php 
         if ($ld_status == 0) { 
          echo 'SUCCESS'; 
         } else if ($ld_status == 1) { 
          echo 'WARNING'; 
         } else { 
          echo 'FAILURE'; 
         } 
        ?> 
        </td> 
      </table>   
    </html> 
+0

它没有工作:( –