当我将鼠标悬停在<tr>
上时,<a>
元素的颜色应更改为白色。更改链接颜色<a>当悬停在<tr>
我试图用jQuery这样的事情:
<script>
$('tr').hover(function(){
$('a').css('color','white');
});
</script>
但这更改所有<tr>
文本颜色。 有什么想法?
当我将鼠标悬停在<tr>
上时,<a>
元素的颜色应更改为白色。更改链接颜色<a>当悬停在<tr>
我试图用jQuery这样的事情:
<script>
$('tr').hover(function(){
$('a').css('color','white');
});
</script>
但这更改所有<tr>
文本颜色。 有什么想法?
有一些方法可以做到。 .hover方法可以有两种功能(通过移动鼠标,鼠标移动了),你可以同时实现改变颜色,样品:
1 - 由JavaScript(jQuery的)
$(document).ready(function(){
$('tr').hover(
function(){
var $this = $(this);
$this.css('background-color', '#fff');
},
function(){
var $this = $(this);
// original color -> $this.css('background-color', $this.data('bgcolor'));
$this.css('background-color', '#000');
}
);
});
您可以使用.data('bgcolor')
以获取颜色由样式attritbute或设置在标签上的原始css设置。
2)或者只是添加CSS
.row {
background-color: #000;
}
.row : hover {
background-color: #fff;
}
,并设置该行
<tr class='row'>
...
</tr>
此行添加到您的CSS文件,忘记了jQuery:
tr:hover a { color: white; }
如果你非常希望你的jQuery代码能够正常工作,那么你只需要将你的hiled行中的锚点作为目标:
$('tr').hover(function(){
$('a', this).css('color','white');
});
我不知道如果它会在你的情况下,我使网站与一个主要颜色和第二个白色。每刷新一次颜色都是随机的,所以我需要悬停元素来改变颜色。所以,我结束了:
#menu-buttons>li{ color:#fff; }
#menu-buttons>li:hover { color: inherit; }
然后我就随机分配颜色与父元素:
$('#menu-buttons').css('color',mainColor);
我正面临着类似的问题;发现这个解决方案是有效的。
div.cntrblk tr:hover td a {
color:rgb(0,0,255);
}
你为什么要使用jQuery?你不能仅仅使用CSS吗? – SmokeyPHP 2012-07-05 19:46:08