这是来自 w3s 网站的 HTML/jquery 代码。如果您在以下位置尝试:Try It W3S
您将看到问题所在。奇数行的不透明度与偶数行不同,这没关系,但我希望文本颜色(或亮度)保持不变。怎么做?我已经通过设置进行了尝试:$("tr td").css("opacity","1.0");
但它没有帮助。
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("tr").css("background-color", "yellow").css("opacity","1.0");
$("tr:odd").css("opacity","0.5");
$("tr td").css("opacity","1.0");
});
</script>
</head>
<body>
<h1>Welcome to My Web Page</h1>
<table border="1">
<tr>
<th>Company</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Germany</td>
</tr>
<tr>
<td>Berglunds snabbkцp</td>
<td>Sweden</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>UK</td>
</tr>
</table>
</body>
</html>