dtcaw02086 2017-11-18 19:59
浏览 156
已采纳

在PHP表格单元格中为特定单词添加颜色

I want to color the word "Pizza" in class "status", which is inside my HTML table, which gets data from a database with PHP.

      <!-- populate table from mysql database -->
        <?php
        while($row=mysqli_fetch_array($records))
        {
            ?>
            <tr>
            <td class="status"><?php echo $row['pojem'];?></font></td>
            <td><font color="brown"><?php echo $row['kratica'];?></font></td>
            <td><font color="brown"><?php echo $row['nem'];?></font></td>
            </tr>
            <?php
        }
    ?>

I have tried the following but it doesn't work

<script>
$('.status:contains("Pizza")').css('color', 'red');
</script>
  • 写回答

2条回答 默认 最新

  • dsarttv037029 2017-11-18 20:20
    关注

    You may use the following jQuery code and set CSS class colord with the color or the style you want.

    $(document).ready(function(){
      $('td.status').each(function(){
       text = $(this).html();
       $(this).html(text.replace('Pizza','<span class="colord">Pizza</span>')); // html is used instead of text
    });
    
    })
    

    Edit

    The text method is replaced with html method to make void HTML escape in the string.

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

报告相同问题?

悬赏问题

  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?
  • ¥15 Jenkins+k8s部署slave节点offline
  • ¥15 微信小游戏反编译后,出现找不到分包的情况
  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)