jquery - 悬停的 CSS 仅适用于 jQuery 的奇数行

标签 jquery css html-table

我有这段代码,它可以很好地交替实际的行,但只悬停在“奇数”行上。

我正在使用以下代码:

    <script type="text/javascript"> 
$(document).ready(function(){
    //jQuery ready is quicker than onload
$(".stripeMe tr").mouseover(function(){$(this).addClass("over");}).mouseout(function(){$(this).removeClass("over");});
$(".stripeMe tr:even").addClass("alt");
});

这是我正在使用的 css

    #table tr.over td{background: #bcd4ec;}
    #table tr.alt td {background: #ecf6fc;}

有什么想法吗?

最佳答案

你的 over style 被你的 alt style 覆盖了。你必须换线。

#table tr.alt td {background: #ecf6fc;}
#table tr.over td{background: #bcd4ec;}

现在 .alt 的优先级低于 .over 因为它的定义较早。

关于jquery - 悬停的 CSS 仅适用于 jQuery 的奇数行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6359985/

相关文章:

Jquery:查找子div的高度并更改父div的高度

javascript - 使用 jQuery 在 HTML 页面中包含 HTML 页面

javascript - 使左侧菜单固定在父容器内

html - 悬停效果 div 位置和边框

python - 内置站点样式的 Web 框架

html - 如何阻止表格自行调整大小以适应屏幕?

javascript - 通过返回 <div> 使用 Ajax/jQuery 加载更多内容

javascript - 如何在 jquery 中追加 4-5 个空格?

html - Internet Explorer 8 中隐藏的顶部 TD 边框

css - 在 HTML 中使用 <h4> 隐藏表格的空行