Jquery 交替行颜色在悬停功能后似乎不起作用
我使用以下 jquery 语句,
$(".resultsdiv:odd").css("background-color", "#fff");
$(".resultsdiv:even").css("background-color", "#EFF1F1");
$('.resultsdiv').hover(function() {
$(this).css('background-color', '#f4f2f2');
},
function() {
$(this).css('background-color', '#fff');
});
Alternate 最初似乎没问题,但将鼠标悬停在 div 元素上后它不起作用...任何建议...
I use the following jquery statements,
$(".resultsdiv:odd").css("background-color", "#fff");
$(".resultsdiv:even").css("background-color", "#EFF1F1");
$('.resultsdiv').hover(function() {
$(this).css('background-color', '#f4f2f2');
},
function() {
$(this).css('background-color', '#fff');
});
Alternate seems to be ok initially but after hover over a div element it doesn't work ... Any suggestion...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我的建议是不要直接操作样式,使用类。所以 CSS:
with:
像这样的调用的问题
是,您无法知道如何将元素重置为其原始状态,因为它的原始颜色也可能已设置为内联样式,就像代码示例中的情况一样。类只是让这类问题变得容易得多。
My suggestion is don't manipulate style directly, use classes. So CSS:
with:
The problem with a call like:
is that you have no way of knowing how to reset the element to its original state because its original colour may have also been set as inline style, as is the case in your code sample. Classes just make this kind of problem much much easier.
我使用以下代码。该表是使用ajax 获取的。 ajax成功后,我触发tableready()函数。在其中我有以下代码,它与带有 zebra 小部件的表格排序器完美配合。
I use the following code. The table is fetched using ajax. After ajaxing is successful, I trigger tableready() function. inside that I have the following code, which works perfectly with table sorter with zebra widget.
我使用此代码来显示替代颜色、鼠标悬停和所选行颜色突出显示。它会起作用
如果您通过 ajax 生成表行,那么只需调用此脚本即可工作。
i used this codes for showing alternate color, mouse over and selected row color highlight.it will work
if your are generating table row by ajax then just call this script it will work.
当鼠标移开时,将行的颜色设置为#fff,这对于奇数行看起来不错,但对于偶数行则不然。
鼠标移出时,您需要检查它是奇数还是偶数,并相应地设置颜色。
When you mouse out you set the color of the row to #fff, this will look fine for odd rows but not even.
On mouseout you'll need to check if it's odd or even and set the color accordingly.