我有以下代码:
<script type = "text/javascript">
function showColors() {
var cells = getElementsbyClass("design");
for (var i = 0, len = cells.length; i < len; ++i) {
cells[i].style.backgroundColor = "#ddd";
}
}
if(document.getElementsByClassName) {
getElementsByClass = function(classList, node) {
return (node || document).getElementsByClassName(classList);
};
</script>
<script type = "text/javascript">
window.onload = function() {
showColors();
}
</script>
table id="foo">
<tbody>
<tr class = "design">
<td>One</td><td>Two</td><td>Three</td>
</tr>
<tr class = "design">
<td>One</td><td>Two</td><td>Three</td>
</tr>
<tr class = "design">
<td>One</td><td>Two</td><td>Three</td>
</tr>
</tbody>
</table>
</body>
我的问题:如何通过 getElementsbyClass() 将第二行设置为不同的颜色。您怎么看,实际代码不起作用:(。请不要使用JQuery或selectivizr。请留在示例中:)。我需要一个动态的例子。我知道css会工作!!!同样重要的是:它应该适用于所有浏览器!!
非常感谢您的回答:)