gpt4 book ai didi

php - 根据 innerText 更改背景颜色?

转载 作者:太空宇宙 更新时间:2023-11-04 14:27:51 24 4
gpt4 key购买 nike

我是 PHP 的新手,我不知道该怎么做。我有一个超大的 CSV 文件,它使用 fget 作为 html 表加载。如何遍历特定列并仅将该列中包含单词"is"的特定单元格的 td 背景色更改为绿色?

作为引用,这是我的代码:

<!DOCTYPE html>
<html>
<head>
<link href="stylesheets/styles.css" rel="stylesheet" />
</head>
<body>
<?php
echo "<table>\n\n";
$f = fopen("market_research.csv", "r");
while (($line = fgetcsv($f)) !== false) {
echo "<tr>";
foreach ($line as $cell) {
if (substr($cell, 0,4) == "http") {
echo "<td>" ."<a href='" . $cell . "'>Go!</a>";
} else
echo "<td>" . htmlspecialchars($cell);
}
echo "<tr>\n";
}
fclose($f);
echo "\n</table></body></html>";


?>

这是我当前的 CSS:

tr {background-color: #f7f7f7;}
body {background-color:#8b9dc3;}
td:first-child {
text-align: center;
font-weight: bold;
padding-left: 5px;
padding-right: 5px;
}

td:nth-child(odd)
{
background-color: #FFFFFF;
}

tr:first-child {
background-color: #FFFFFF !important;
text-align: center;
font-weight: bold;
font-size: 110%;
height: 50px;
}

td {
padding-left: 5px;
padding-right: 5px;
}

最佳答案

你可以这样设置:

希望对你有帮助

您需要添加 data-attr到你的元素<p>同时生成<td>使用fget()

<p data-val="Yes">Yes</p>

你的 CSS 应该是这样的:

p[data-val="Yes"] {background-color:green;}

Working Example

关于php - 根据 innerText 更改背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19406787/

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