當我測試代碼時,如果它正在使用靜態表格運行,則它工作正常。但是當我在生成動態表的頁面上運行它時,什麼都不會發生。使用javascript突出顯示動態php表中的單元格
JavaScript代碼
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"></script>
<script type="text/javascript">
$('#Weekly td').each(function() {
if ($(this).text() == 'Yes') {
$(this).closest('td').css('background-color', 'yellow');
}
});
</script>
PHP代碼
if ($WeeklyResult->num_rows > 0){
echo "<Table id=Weekly>";
$headerRow = TRUE;
while ($row = $WeeklyResult->fetch_assoc()){
if($headerRow){
$headerRow = FALSE;
echo "<tr>";
foreach (array_keys($row) as $header){
echo"<th>$header</th>";
}
echo "</tr>";
}
echo "<tr>";
foreach ($row as $value){
echo "<td>$value</td>";
}
echo "</tr>";
}
echo "</table>";
}
在動態生成你在哪裏添加ID **每週**。我認爲它應該分配到一些行。 –