gpt4 book ai didi

javascript - 为 PHP 表格单元格中的特定单词添加颜色

转载 作者:行者123 更新时间:2023-11-28 17:09:07 24 4
gpt4 key购买 nike

我想给“status”类中的“Pizza”这个词着色,它在我的 HTML 表中,它使用 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
}
?>

我已经尝试了以下但它不起作用

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

最佳答案

您可以使用以下 jQuery 代码,并使用您想要的颜色或样式设置 CSS 类 colord

$(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
});

})

编辑

text方法被替换为html方法,使字符串中的void HTML转义。

关于javascript - 为 PHP 表格单元格中的特定单词添加颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47370428/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com