Slickgrid,在悬停时更改行颜色

时间:2014-01-11 11:18:19

标签: jquery slickgrid

我有一个slickgrid网格,我想更改行悬停时的行背景颜色。我试过这个:

$(".slick-row").mouseenter(function(){ 
    $(this).css("background-color","red"); 
}).mouseleave(function(){ 
    $(this).css("background-color","white"); 
});

但它不起作用。有办法吗?

3 个答案:

答案 0 :(得分:8)

为什么不直接添加CSS?

.slick-row:hover{
    background: none repeat scroll 0 0 red;
}

答案 1 :(得分:4)

由于您使用的是slickgrid,目标行将是动态的,因此请使用event delegation注册事件处理程序。

$(document).on('mouseenter', ".slick-row", function () {
    $(this).css("background-color", "red");
}).on('mouseleave', ".slick-row", function () {
    $(this).css("background-color", "white");
});

同时将选择器$(document)更改为更具体的选项。

答案 2 :(得分:-1)

试试这个:

EXAMPLE

$(".slick-row").hover(function(){ 
    $(this).css("background-color","red"); 
}).mouseout(function(){ 
    $(this).css("background-color","white"); 
});
相关问题