【发布时间】:2018-04-08 20:31:16
【问题描述】:
尝试创建可滚动的表格。
我试过了:
<style>
table.scroll tbody,
table.scroll thead { display: block; }
table.scroll tbody {
height: 300px;
overflow-y: auto;
overflow-x: hidden;
}
</style>
<script>
// Change the selector if needed
var $table = $('table.scroll'),
$bodyCells = $table.find('tbody tr:first').children(),
colWidth;
// Adjust the width of thead cells when window resizes
$(window).resize(function() {
// Get the tbody columns width array
colWidth = $bodyCells.map(function() {
return $(this).width();
}).get();
// Set the width of thead columns
$table.find('thead tr').children().each(function(i, v) {
$(v).width(colWidth[i]);
});
}).resize(); // Trigger resize handler
</script>
我想要一个有滚动效果的表格tbody
【问题讨论】:
标签: html css html-table