Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jQuery的表行背景色_Jquery - Fatal编程技术网

使用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”

我有一个简单的表,当用户悬停行元素时,我使用jQuery更改行颜色

$('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:'' });
});