2 回答
TA贡献1865条经验 获得超7个赞
您必须为任何行添加类并为此类设置颜色
function multiplication_table($rows, $cols){
echo "<table width =\"500\" height=\"500\" border=\"50\">";
for ($row = 1; $row <= $rows; $row++){
echo'<tr class="row'+$row+'">';
for ($col = 1; $col <= $cols; $col++)
echo '<td align = "center">' .$col*$row.'</td>';
echo '</tr>';
}
echo"</table>";
}
并在 css 中设置颜色,例如
.row1 , .row1 td
{
background:red;
}
TA贡献1830条经验 获得超9个赞
您可以添加background color到行:
function multiplication_table($rows, $cols){
echo "<table width =\"500\" height=\"500\" border=\"50\">";
for ($row = 1; $row <= $rows; $row++){
// Generate Random Color
$color = "#".substr(md5(rand()), 0, 6);
// Apply color to row
echo'<tr style="background-color:'.$color.'">';
for ($col = 1; $col <= $cols; $col++)
echo '<td align = "center">' .$col*$row.'</td>';
echo '</tr>';
}
echo"</table>";
}
- 2 回答
- 0 关注
- 138 浏览
添加回答
举报