【发布时间】:2011-12-15 10:53:21
【问题描述】:
divs 中有两个 HTML 表格并排浮动。第二个div 可以在水平方向滚动,因此实际上它看起来像一个大表,其中前几列被“冻结”,其他列可以滚动。
当用户将鼠标悬停在表格上时,以下 jQuery 非常适合突出显示表格中的一行:
$("table.grid tr:not(:first-child)")
.hover(
function () { $(this).addClass("highlight"); },
function () { $(this).removeClass("highlight"); }
);
请注意,:not(:first-child) 可防止标头被突出显示。
我该如何修改它,以便它也突出显示另一个表中的相应行(也有一个 grid 类)?
换句话说,如果我将鼠标悬停在任一表中的nth 行上,则两个表中的nth 行都会突出显示。
编辑:HTML 看起来像:
<div>
<div style="float: left">
<table id="names" class="grid">
<tr><th>Last</th><th>First</th></tr>
<tr><td>Smith</td><td>John</td></tr>
<!-- etc -->
</table>
</div>
<div style="float: left; overflow-x: scroll">
<table id="results" class="grid">
<tr><th>Test 1</th><th>Test 2</th></tr>
<tr><td>50%</td><td>70%</td></tr>
<!-- etc -->
</table>
</div>
<div style="clear: both">
</div>
</div>
【问题讨论】:
标签: jquery css html-table jquery-selectors