将鼠标悬停在两张桌子上?

Pau*_*gor 4 html css jquery

<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;
}
Run Code Online (Sandbox Code Playgroud)

现场:http://jsfiddle.net/KzzW8/

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

 `<tr class="here<? echo $i ?> yes">`
Run Code Online (Sandbox Code Playgroud)

我想鼠标悬停TR.here1将任何内容转换TR.here1为RED,其中下属TD在组中:(aaa1,bbb1,ccc1,ddd1),无论它在哪个表中.

我相信我可以使用jQuery.这可能吗?

zer*_*kms 5

http://jsfiddle.net/KzzW8/1/

$('tr').hover(function() {
    var cls = $(this).prop('class').match(/here\d+/);
    if (cls) {
        $('.' + cls).addClass('hover');
    }
}, function() {
    $('.yes.hover').removeClass('hover');
});?
Run Code Online (Sandbox Code Playgroud)

所以你在悬停事件中获取here*类并将类.hover应用于具有相同类的所有行.在悬停时 - 您删除所有额外添加的类