2014-01-11 188 views
1

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

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

但它不工作。有没有办法做到这一点?

回答

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)另外更改为更具体的一个。

+0

听起来像工作,但只有奇数行具有背景,当他们徘徊他们的偶数行号。 – OussamaLord

+0

看起来像你的一些CSS是覆盖风格..你有奇怪的行不同的风格 –

+0

@OussamaLord我刚刚在slickgrid示例页面中测试它http://mleibman.github.io/SlickGrid/examples/ example1-simple.html,看起来没问题 - 进入页面 - >打开浏览器控制台 - >复制并粘贴脚本并执行它 - >将鼠标悬停在行上 –

-1

试试这个:

EXAMPLE

$(".slick-row").hover(function(){ 
    $(this).css("background-color","red"); 
}).mouseout(function(){ 
    $(this).css("background-color","white"); 
}); 
+0

不与电网 – OussamaLord

+0

工作-1,因为悬停应该是抽象的从mousein /出它封装并也弃用,取而代之的mouseenter的/诺瓦离开天的路程。 –

7

为什么不只是添加CSS?

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