// nth-child(2)
$('table tr td:nth-child(2)').css('background-color','red');

// :nth-child(2n)
$('table tr td:nth-child(2n)').css('background-color','red');

本文通过实例展示了如何使用CSS选择器:nth-child(2)及:nth-child(2n)来为HTML表格中的特定单元格设置背景颜色。具体操作包括对所有位于偶数位置的单元格进行样式修改。
// nth-child(2)
$('table tr td:nth-child(2)').css('background-color','red');

// :nth-child(2n)
$('table tr td:nth-child(2n)').css('background-color','red');

5818

被折叠的 条评论
为什么被折叠?