使用jQuery的表行背景色
我有一个简单的表,当用户悬停行元素时,我使用jQuery更改行颜色使用jQuery的表行背景色,jquery,Jquery,我有一个简单的表,当用户悬停行元素时,我使用jQuery更改行颜色 $('tr').on('mouseenter', function(){ $(this).css({background:'#f00'}); }); $('tr').on('mouseout', function(){ $(this).css({background:''}); }); 当用户将鼠标从A列移动到B列(在同一行上)时,将触发mouseout事件 jsFiddle 测试用例:将鼠标移到包含“Foo”
$('tr').on('mouseenter', function(){
$(this).css({background:'#f00'});
});
$('tr').on('mouseout', function(){
$(this).css({background:''});
});
当用户将鼠标从A列移动到B列(在同一行上)时,将触发mouseout
事件
jsFiddle
测试用例:将鼠标移到包含“Foo”的单元格上。将鼠标右移到包含“条”的单元格。该行应保持红色,但不保持红色
在IE11和铬42.0.2311.152m中测试。CSS是不合适的,因为我实际使用的选择器。(附ia a)。解决方法:
将mouseenter
/mouseout
事件应用于td
,然后使用$(this.parent().css({background:…})代码>取而代之
jsidle.解决方法:
将mouseenter
/mouseout
事件应用于td
,然后使用$(this.parent().css({background:…})代码>取而代之
jsFIDLE。您可以使用CSS处理样式:
tr:hover {
background-color:#f00;
}
您可以使用CSS处理样式:
tr:hover {
background-color:#f00;
}
鼠标指针离开任何子对象时触发mouseout事件
元素以及选定的元素
mouseleave事件仅在鼠标指针离开时触发
选定的元素
使用mouseleave
事件而不是mouseout
:
$('tr').on('mouseenter', function(){
$(this).css({background:'#f00'});
});
$('tr').on('mouseleave', function(){
$(this).css({background:''});
});
鼠标指针离开任何子对象时触发mouseout事件
元素以及选定的元素
mouseleave事件仅在鼠标指针离开时触发
选定的元素
使用mouseleave
事件而不是mouseout
:
$('tr').on('mouseenter', function(){
$(this).css({background:'#f00'});
});
$('tr').on('mouseleave', function(){
$(this).css({background:''});
});
您可以更好地使用
$('tr').hover(function () {
$(this).css({background:'#f00' });
}, function () {
$(this).css({background:'' });
});
您可以更好地使用
$('tr').hover(function () {
$(this).css({background:'#f00' });
}, function () {
$(this).css({background:'' });
});
CSS不合适-实际上我使用的是更复杂的选择器。编辑made,Thank.CSS不合适-实际上我使用的是更复杂的选择器。编辑好了,谢谢。
$('tr').hover(function () {
$(this).css({background:'#f00' });
}, function () {
$(this).css({background:'' });
});