2012-03-12 180 views
2

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

#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).parent(),但这会给我整行。我想要的是突出整个行,除了最后一个单元格。

有人会知道一个解决方案吗?

干杯。

+1

$(本).siblings()查找( 'TD:没有(:最后一个孩子)')。添加/ removeClass()?没有检查,但看到没有理由不工作。 – 2012-03-12 23:32:24

+0

你的CSS选择器是错误的。 使用'#mysearchtable tr td:not(:last-child):hover' 使用原始选择器,您会说“突出显示行,但不突出显示最后一个单元格”,这是没有意义的,因为您突出显示容器(行)而不是容器内的单个单元格。 – 2012-03-12 23:43:03

+0

这不是他的选择者所说的。它是“当行被徘徊时,突出显示单元格,但不是最后一个。”你的是,“当一个不是最后一个的细胞被徘徊时”。 – marramgrass 2012-03-12 23:44:44

回答

4

未经检验的,但尝试:

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

谢谢你的工作! – FruitDealer 2012-03-12 23:41:16

1

在这里,您可以使用这种方式。 Jsfiddle demo

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

相关问题