doumiebiao6827 2015-09-06 08:16
浏览 36
已采纳

检查表格单元格块是否有数据,如果是,则更改样式

I created a table that I am using as a draft board. There are users and then players they have to pick. I am wondering if a user has picked a player if there is anyway I can style that cell block in a different color style to show that block more significantly that it was picked. Then the empty blocks leave the normal styling.

I created a fiddle to show the table somewhat how it looks.

https://jsfiddle.net/zmggLd57/

So the cells that have names in them I was wondering if I could make them a different color.

<table class="draft_border_table">
<tr>
    <th class="draft_table_number_th">RND</th>
<?php
// Output usernames as column headings
$userResults = mysqli_query($con, 'SELECT * FROM user_players ORDER BY `id`');
while ($userPlayer = mysqli_fetch_array($userResults)) {
    $userPlayerStore[] = $userPlayer;
    echo '<th class="draft_table_th"><div>' . $userPlayer['username'] . '</div></th>';
}
?>
</tr>
<?php
// Output each user's player 1-14 in each row
$totalPlayerNumbers = 14;
for ($playerNum = 1; $playerNum <= $totalPlayerNumbers; $playerNum++) {
    echo '<tr><td><div class="draftBorder">' . $playerNum . '</div></td>';
    foreach ($userPlayerStore as $userPlayer) {
        echo '<td class="draft_table_td">' . $userPlayer['player' . $playerNum] . '</td>';
    }
    echo '</tr>';
}
?>
</table>
  • 写回答

2条回答 默认 最新

  • doudou20145 2015-09-06 08:37
    关注

    i hope, it will help you

    $("td.draft_table_td").each(function(){
    if($(this).text()!=""){
    $(this).css("background-color","blue");
    }
    });
    

    https://jsfiddle.net/7w3c384f/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?