我在其中一个jQuery书中看到,你可以突出显示正在排序的列.
$('th.sortable').click(function() {
var $th = $(this);
var column = $th.index();
var $table = $th.closest('table');
var rows = $table.find('tr:not(:has(th))').get();
Run Code Online (Sandbox Code Playgroud)
问:如何将"hightlight"类添加到单击的列中的每个单元格?
有一个nth-child你可以在这种情况下使用选择.
$('th.sortable').click(function() {
var $th = $(this),
column = $th.index(),
$table = $th.closest('table');
$table.find('tr td:nth-child(' + (column+1) + ')').addClass('highlight');
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
219 次 |
| 最近记录: |