Jquery 在两张桌子上悬停上课? aaa1bbb1 aaa2bbb2 aaa3bbb3 ccc1ddd1 ccc2ddd2 ccc3ddd3 .是:悬停{ 背景色:红色; }

Jquery 在两张桌子上悬停上课? aaa1bbb1 aaa2bbb2 aaa3bbb3 ccc1ddd1 ccc2ddd2 ccc3ddd3 .是:悬停{ 背景色:红色; },jquery,html,css,Jquery,Html,Css,现场: 上表是使用以下PHP生成的: <table border=2> <tr class="here1 yes"> <td>aaa1</td><td>bbb1</td> </tr> <tr class="here2 yes"> <td>aaa2</td><td>bbb2</td> <

现场:

上表是使用以下PHP生成的:

<table border=2>
    <tr class="here1 yes">
        <td>aaa1</td><td>bbb1</td>
    </tr>
    <tr class="here2 yes">
        <td>aaa2</td><td>bbb2</td>
    </tr>

    <tr class="here55 yes">
        <td>aaa3</td><td>bbb3</td>
    </tr>
</table>


<table border=2>
    <tr class="here1 yes">
        <td>ccc1</td><td>ddd1</td>
    </tr>
    <tr class="here2 yes">
        <td>ccc2</td><td>ddd2</td>
    </tr>

    <tr class="here55 yes">
        <td>ccc3</td><td>ddd3</td>
    </tr>
</table>


.yes:hover {
   background-color: red;
}
`


因此,您可以在hover事件中获取
here*
类,并将class
应用于具有相同类的所有行。悬停时-您删除了所有额外添加的类

您能更清楚地解释您想要做什么吗?我不明白您的问题如果我将鼠标移到类1上,则该类应为背景色:第页上所有类1中的红色(在我的两个表中的示例中)在现实世界的DOM中,如果有许多其他节点可以这样做,可能会更友好,但本质上仍然是相同的解决方案。@Beetroot Beetroot:事实上,最终决定取决于目标和当前布局
 `<tr class="here<? echo $i ?> yes">`
$('tr').hover(function() {
    var cls = $(this).prop('class').match(/here\d+/);
    if (cls) {
        $('.' + cls).addClass('hover');
    }
}, function() {
    $('.yes.hover').removeClass('hover');
});​