使用jQuery替换表的行和列颜色
我正在尝试使用以下代码来交替表中的行和列使用jQuery替换表的行和列颜色,jquery,html,Jquery,Html,我正在尝试使用以下代码来交替表中的行和列 <script> $(document).ready(function() { $("table#id2 td:even").css("background-color", "LightGray"); $("table#id2 tr:even").css("background-color", "LightBlue"); $("table#id2 tr:odd").css("background-color",
<script>
$(document).ready(function()
{
$("table#id2 td:even").css("background-color", "LightGray");
$("table#id2 tr:even").css("background-color", "LightBlue");
$("table#id2 tr:odd").css("background-color", "LightYellow");
});
</script>
我希望我的桌子看起来像这样:
Gray Blue
Gray Yellow
Gray Blue
Gray Yellow
Gray Blue
Yellow Yellow
Gray Blue
Yellow Yellow
这是否可能使用td:偶数、tr:odd等 基本上,仅对
奇数行应用颜色
尝试:
$(文档).ready(函数()
{
$(“table#id2 td:偶数”).css(“背景色”、“浅灰色”);
$(“table#id2 tr:even”).css(“背景色”、“浅蓝色”);
$(“table#id2 tr:odd td”).css(“背景色”、“淡黄色”);
});
基本上,仅对奇数行应用颜色
尝试:
$(文档).ready(函数()
{
$(“table#id2 td:偶数”).css(“背景色”、“浅灰色”);
$(“table#id2 tr:even”).css(“背景色”、“浅蓝色”);
$(“table#id2 tr:odd td”).css(“背景色”、“淡黄色”);
});
您必须在tr:odd td
$("table#id2 td:even").css("background-color", "LightGray");
$("table#id2 tr:even").css("background-color", "LightBlue");
$("table#id2 tr:odd td").css("background-color", "LightYellow");
这里有一把小提琴显示了一个解决方案:您必须在tr:odd td
$("table#id2 td:even").css("background-color", "LightGray");
$("table#id2 tr:even").css("background-color", "LightBlue");
$("table#id2 tr:odd td").css("background-color", "LightYellow");
这里有一把小提琴显示了一个解决方案:为什么是jquery?为什么不是简单的css?看看这个链接为什么是jquery?为什么不简单的css?看看这个链接谢谢!当我尝试将td添加到显示为黄色的代码时,语法错误。谢谢!当我尝试将td添加到显示为黄色的代码时,语法错误。