我在上面看到这个帖子突出显示偶数列但我可以只突出显示选定的列吗?
这是他们使用的代码:
$("table.Table22 > tbody > tr > td:nth-child(even)").css("background","blue");
但我想: 注意:class="highlight"
将在选定的列上,所以如果我选择第 3 列class="highlight"
将从第 2 列中删除并添加到第 3 列中。jQuery 需要根据所选列添加类。
<table class="tbl">
<tr>
<th class="firstColumn">
Cell 1:Heading
</th>
<th class="highlight">
Selected column so this should be highlighted
</th>
<th>
Cell 3:Heading
</th>
<th>
Cell 4:Heading
</th>
<th>
Cell 5:Heading
</th>
</tr>
<tr>
<td>
Cell 1:Row 1
</td>
<td class="highlight">
Selected column so this should be highlighted
</td>
<td>
Cell 3:Row 1
</td>
<td>
Cell 4:Row 1
</td>
<td>
Cell 5:Row 1
</td>
</tr>
<tr>
<td>
Cell 1:Row 2
</td>
<td class="highlight">
Selected column so this should be highlighted
</td>
<td>
Cell 3:Row 2
</td>
<td>
Cell 4:Row 2
</td>
<td>
Cell 5:Row 2
</td>
</tr>
</table>
您可能想看一下jQuery tableHover 插件为了达成这个。然后使用这样的东西
$('table.tbl').tableHover({
colClass: 'hover',
clickClass: 'click',
headCols: true,
footCols: true
});
EDIT:
像这样的东西吗?
工作演示 - 单击任意单元格,突出显示该列
演示中的代码 -
$(function() {
var rows = $('table.tbl tr');
rows.children().click(function() {
rows.children().removeClass('highlight');
var index = $(this).prevAll().length;
rows.find(':nth-child(' + (index + 1) + ')').addClass('highlight');
});
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)