jQuery高亮显示表行除了顶部一行

时间:2013-07-23 17:28:06

标签: jquery html-table row highlight

$('table tr').mouseover(function() {
    $(this).addClass('hovered');
}).mouseout(function() {
    $(this).removeClass('hovered');
});

以下代码可让我轻松突出鼠标悬停时的每个表格行 - 但是,我不想突出显示第一行。

任何想法如何实现这一目标?

2 个答案:

答案 0 :(得分:4)

试试这个 -

$('table tr:not(:first)').mouseover(function() {
    $(this).addClass('hovered');
}).mouseout(function() {
    $(this).removeClass('hovered');
});

或者您可以使用gt

$('table tr:gt(0)')

答案 1 :(得分:1)

$('table tr:gt(0)').mouseover(function() {
    $(this).addClass('hovered');
}).mouseout(function() {
    $(this).removeClass('hovered');
});

如果你不想查找它,:gt()修饰符代表greater than,其中parans内的数字是元素的从零开始的索引(来自返回的元素集合)选择器,在本例中为table tr)。反过来,:lt()less than:eq()为等,:even:odd不言自明。

相关问题