我已按照 this fiddle 中给出的方式修复了 html 表的列.同样,我试图只修复表格的标题行,
var $table = $('.table');
var $fixedColumn = $table.clone().insertBefore($table).addClass('fixed-column');
$fixedColumn.find('tbody').remove();
$fixedColumn.find('thead th').each(function (i, elem) {
$(this).width($table.find('tbody tr:first td:eq(' + i + ')').width());
});
在 this fiddle 中给出.但是标题没有固定。缺少什么?
最佳答案
这个怎么样??
<tr class="fixed">
<th>#</th>
<th>Table heading</th>
<th>Table heading</th>
<th>Table heading</th>
<th>Table heading</th>
<th>Table heading</th>
<th>Table heading</th>
</tr>
CSS
.fixed
{
position:fixed;
background:gray;
}
你可以试试这个 EXAMPLE 如果您更感兴趣的话!
关于javascript - 修复 html 表格的表头在顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30043475/