我一直在嘗試創建一個主要使用PHP的流行語賓果遊戲。我從一個在特定網站上找到的25個單詞的數組中爲關鍵字添加一個特定的類。現在我只想使用jquery對所有單元格中的行進行樣式設置,但我無法弄清楚,這是我目前所掌握的。只有當所有的td都具有某個類時,如何才能將類添加到tr?
$('td.check').parent('tr').addClass('bingo');
PHP:
function bingo() {
$buzzwords = array(
"kaos",
"mega",
"super",
"kris",
"tragedi",
"döds",
"succé",
"avslöjar",
"chocken",
"terror",
"attack",
"mardröm",
"rekord",
"galen",
"knark",
"attentat",
"extrem",
"kollaps",
"kränkt",
"skräll",
"myten",
"problem",
"varning",
"extra",
"besked"
);
shuffle($buzzwords);
$inAb = array();
$bingocard = "<table class='tabell'>";
$bingocard .= "<thead><tr>";
$bingocard .= "<th>B</th>
<th>I</th><th>N</th>
<th>G</th><th>O</th>";
$bingocard .= "</tr></thead>";
$bingocard .= "<tbody>";
$bingocard .= "<tr>";
for($cell=0; $cell<25; $cell++)
{
$rowend = ($cell + 1) % 5;
$homepage = file_get_contents('http://www.example.com/');
$value = $buzzwords[$cell];
$antal = substr_count($homepage, $buzzwords[$cell]);
if ($antal > 0) {
$bingocard .= "<td class='check' style='color: red;'>"
. $buzzwords[$cell] . "</td>";
array_push($inAb,$buzzwords[$cell]);
}
else {
$bingocard .= "<td>"
. $buzzwords[$cell] . "</td>";
}
if($rowend == 0 && $cell < 24) {
$bingocard .= "</tr><tr>";
}
}
$bingocard .= "</tr>";
$bingocard .= "</tbody>";
$bingocard .= "</table>";
echo $bingocard;
}
bingo();
這幾乎做到了,謝謝! 由於某種原因,它也將課程添加到了我的課堂,儘管你知道爲什麼嗎? – oceansmoving
已更新的答案。 –
優秀,非常有幫助! – oceansmoving