Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.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悬停在表行上,带有.live帮助_Jquery_Css - Fatal编程技术网

jquery悬停在表行上,带有.live帮助

jquery悬停在表行上,带有.live帮助,jquery,css,Jquery,Css,我有一个表,我使用以下工具动态创建行: $('#AjaxResultTable > tbody:last').append('<tr class="row"><td class="expandResult" title="Click to expand/collapse">&#43;</td>' + id + name + suburb + state + zip + '</tr>').hide().fadeIn(200); 但那不

我有一个表,我使用以下工具动态创建行:

$('#AjaxResultTable > tbody:last').append('<tr class="row"><td class="expandResult" title="Click to expand/collapse">&#43;</td>' + id + name + suburb + state + zip + '</tr>').hide().fadeIn(200);
但那不起作用,所以我试着

$('#AjaxResultTable tr').hover(function () {
    $(this).css('background-color', '#f5f5f5');
}, function () {
    $(this).css('background-color', '#fff');
});
$('#AjaxResultTable tr').live('hover', function () {
    $(this).css('background-color', '#f5f5f5');
}, function () {
    $(this).css('background-color', '#fff');
});
当我将鼠标悬停在一行上时,它会改变背景色,但当我不在时,它不会变回白色

有什么建议吗


提前感谢。

我将制作一个简单的事件处理程序,用于切换类

JS

CSS

编辑:同样在您的示例中,该属性应被称为
backgroundColor
(而不是
backgroundColor

编辑2:.live()有几个注意事项,其中一个是与.hover()绑定。参见API文档


希望这有帮助

我会制作一个简单的事件处理程序来切换类

JS

CSS

编辑:同样在您的示例中,该属性应被称为
backgroundColor
(而不是
backgroundColor

编辑2:.live()有几个注意事项,其中一个是与.hover()绑定。参见API文档


希望这有帮助

您可以使用
.mouseleave()
侦听器。。看看这里:

您可以使用
.mouseleave()
监听器。。请看这里:

您需要将背景颜色应用于td/th而不是tr。在这种情况下,基于类的系统更可取

$('#AjaxResultTable tr').hover(function () {
  $(this).addClass('hover');
}, function () {
  $(this).removeClass('hover');
});

tr.hover td, tr.hover th { background-color: #f5f5f5; }

您需要将背景色应用于td/th,而不是tr。在这种情况下,最好使用基于类的系统

$('#AjaxResultTable tr').hover(function () {
  $(this).addClass('hover');
}, function () {
  $(this).removeClass('hover');
});

tr.hover td, tr.hover th { background-color: #f5f5f5; }

我建议严格使用css。如果您的页面上有很多内容,特别是使用live处理程序,您将开始看到性能下降

这样的css选择器:将更改悬停行中所有td的背景颜色

#YourTableId tbody tr:hover td
{
    background-color:#F0F6Fc; 
}

我建议严格使用css。如果您的页面上有很多内容,特别是使用live处理程序,您将开始看到性能下降

这样的css选择器:将更改悬停行中所有td的背景颜色

#YourTableId tbody tr:hover td
{
    background-color:#F0F6Fc; 
}

是的,我也会在Css中更改演示样式。。 有些东西活在已经被安置的地方

#yourTableID tbody td:hover tr
{
   backgroundColor:#F0F6Fc;
    color: #FFF;
}

or .yourTableClass tr:hover
{
   backgroundColor:#F0F6Fc;
    color: #FFF;
}
我也认为它在这里,但如果你正在使用IE…7-无论我建议使用什么
文件

是的,我也会在Css中更改演示样式。。 有些东西活在已经被安置的地方

#yourTableID tbody td:hover tr
{
   backgroundColor:#F0F6Fc;
    color: #FFF;
}

or .yourTableClass tr:hover
{
   backgroundColor:#F0F6Fc;
    color: #FFF;
}
我也认为它在这里,但如果你正在使用IE…7-无论我建议使用什么 文件