【问题标题】:jQuery highlight table row except top onejQuery 突出显示除顶部之外的表格行
【发布时间】:2013-07-22 22:14:46
【问题描述】:
$('table tr').mouseover(function() {
    $(this).addClass('hovered');
}).mouseout(function() {
    $(this).removeClass('hovered');
});

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

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

【问题讨论】:

  • 感谢大家如此出色、快速和有效的回复。赞赏。
  • 如果第一行是表头,那么您应该将其包装在<thead> 标记中,并改用table tbody tr 选择器。

标签: jquery html-table row highlight


【解决方案1】:

试试这个 -

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

或者你可以使用gt

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

【讨论】:

  • 完美! - 多么容易!
  • 您必须等待 15 分钟。
【解决方案2】:
$('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 是不言自明的。

【讨论】:

    猜你喜欢
    • 2012-03-29
    • 2010-10-20
    • 1970-01-01
    • 1970-01-01
    • 2012-08-06
    • 2013-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多