<table>
<tr><td>First Row</td><td>2 Row</td><td>1 last</td></tr>
<tr><td>Middle Row</td><td>2 Row</td><td>2 last</td></tr>
<tr><td>Last Row</td><td>2 Row</td><td>3 last</td></tr>
</table>
$('tr').each(function(index) {
$("td:last").css({backgroundColor: 'yellow', fontWeight: 'bolder'});
});
直播:http://jsfiddle.net/DxVG5/1/
为什么这只对最后 3 个有效,但对最后 1 个和最后 2 个无效?我该如何解决?
最佳答案
您的示例将获取每个 tr
中的最后一个 td
,因为使用 :last 字面上获取 table< 中的最后一个
。试试这个:td
/
$('tr td:last-child').css({
backgroundColor: 'yellow',
fontWeight: 'bolder'
});
关于javascript - :last for table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7470665/