2010-12-14 70 views
0

我刚刚开始使用jQuery,遇到了一些麻烦。jQuery摆脱:悬停下划线?

得到了一张缩略图表,我想让每个单元格在我将鼠标悬停在其中的图片上时突出显示。得到那部分工作。但我也希望单元格内的图片不要有下划线 - 这是从样式表a:hover{text-decoration:underline}继承而来的。这是我卡住的地方,我不认为我设定的是正确的。

我需要使用内联样式,所以我的jQuery的样子:

$('[name*=thumb]').hover(
    function() { 
    //as we hover over an item, change it's background, attempt to vaquish pesky underline 
    $('#' + $(this).attr('id').replace('thumb', 'thumbcontainer')).css('background-color', '#cccccc'); 
    $('#' + this).css('text-decoration', 'none'); //doesn't work : (
    }, 
    function() { 
    //fix bgs of items we're not hovering on 
    $('#' + $(this).attr('id').replace('thumb', 'thumbcontainer')).css('background-color', '#ffffff'); 
    } 
); 

我的HTML看起来像这样:

<td name="thumbcontainer8" id="thumbcontainer8"><a href="#" name="thumb8" id="thumb8"><img src="..." /></a></td> 
<td name="thumbcontainer9" id="thumbcontainer9"><a href="#" name="thumb9" id="thumb9"><img src="..." /></a></td> 

回答

2

什么:

$(this).css('text-decoration', 'none'); 
3

这是不是规则在样式表做的伎俩?

a:hover img{text-decoration:none} 
+1

我必须使用内联样式。 – 2010-12-14 18:02:52

+1

这是CSS的用途。使用jquery添加/删除css标签 – 2010-12-14 18:03:20