根据属性状态更改颜色。 HTML,JavaScript

时间:2018-07-27 22:46:55

标签: javascript jquery html

我需要帮助。

我正在开发一个Web应用程序来注册丢失的对象。

缺少的对象显示在表上。对象的属性等于0,表示未交付。 交付后,其属性值等于1。

我想用绿色背景突出显示已交付的对象(属性等于1)的行,例如绿色。

lost objects

我的桌子:

  <tr>

            <th scope="col">Description of objects </th>
            <th scope="col">local</th>
            <th scope="col"> who find ?</th>
            <th scope="col">With value of without value</th>
            <th scope="col">Destination actualy</th>
            <th scope="col">When it has found</th>
            <th scope="col">When is has delivery</th>
            <th scope="col"> State of objects</th>

            <th scope="col"> Ações </th>
          </tr>    

现在使用带有Mysql的PHP 7

$rs = $connection->prepare("SELECT * FROM Perdidos");
$rs_users = $connection->prepare("SELECT * FROM users");
$registro_users = $rs_users->fetch(PDO::FETCH_OBJ);

if($ rs-> execute()和$ rs_users-> execute()) {

while($registro = $rs->fetch(PDO::FETCH_OBJ)) 
{



    echo "<td>" . $registro->description_Perdidos. "</td>";
    echo "<td>" . $registro->local_Perdidos. "</td>";
    echo "<td>" . $registro->whoFind_Perdidos. "</td>";
    echo "<td>" . $registro->withValueOrWithOutValue_Perdidos. </td>";
    echo "<TD>" . $registro->destinationActualy_Perdidos . "</TD>";
    echo "<TD>" . $registro->WhenIsHasFound_Perdidos. "</TD>";
    echo "<TD>" . $registro->WhenIsHasDelivery_Perdidos . "</TD>";
    echo "<TD>" . $registro->stateOfObjects         . "</TD>";
    echo "<TD>";
    echo "</TD>";

回显“”;

2 个答案:

答案 0 :(得分:1)

在与您的对象属性(0或1)对应的每一行级别添加data-attr属性,您可以使用以下示例应用样式:

$('#tableId').find('tr[data-attr="1"]').css("background-color", "green")

答案 1 :(得分:0)

第一件事-我认为您在while循环内的<tr>元素周围缺少<td>标记。

在while循环中,您可以检查物品是否已交付。如果是这样-将class='delivered'放在<tr>

然后,您可以使用CSS设置具有“已交付”类的行的样式,如下所示:

.delivered { 
  background: #eee
}