Jquery悬停,高亮显示除最后一个单元格之外的表行

Jquery hover, highlight table row except last cell

本文关键字:单元格 最后一个 悬停 高亮 显示 Jquery      更新时间:2023-09-26

我想将这个css行为转换为jquery悬停语句(因为IE7/8不支持css3)。基本上,当鼠标悬停在一行上时,我希望除了最后一个单元格外,整个行都高亮显示。

#mysearchtable tr:hover td:not(:last-child)
{
  background-color: #444444;
}

我试过使用这个:

$("#mysearchtable tr td:not(:last-child)").hover(
 function () { $(this).addClass('hoverclass') }, 
 function () { $(this).removeClass('hoverclass') });

问题是$(this)只返回了悬停在上面的实际单元格。我可以尝试使用$(this).Pparent(),但这会给我整个行。我想要的是高亮显示整行,除了最后一个单元格。

有人知道解决方案吗?

干杯。

未测试,但尝试:

$("#mysearchtable tr").hover(
    function () { $(this).find("td:not(:last-child)").addClass('hoverclass') }, 
    function () { $(this).find("td:not(:last-child)").removeClass('hoverclass') }
);

这里可以使用这种方式。Jsfidle演示

$("table td").not('td:last').hover(function() {
    $(this).css('background-color','red');
});