【发布时间】:2018-11-10 17:56:28
【问题描述】:
我有一个动态表格,我希望在滚动表格时保持其头部固定。 表格如下。这基本上做的是,javascript将使用输入字段中的数字并创建包含的任意数量的行。我为表格使用了固定高度。但是当表格增长超过高度时给定然后我必须向下滚动。然后,thead 也会上升并变得不可见,因此任何修复 thead 的方法都值得赞赏。
注意:我已经阅读了这里几乎所有与同一主题相关的内容,但它似乎对我不起作用。
HTML
<div class="container-fluid"" style="width: 90%" style="height: 90%">
<table id="tableAddResults" class="table table-hover" cellspacing="0">
<thead>
<tr>
<th scope="col">Index No</th>
<th scope="col">Correct A</th>
<th scope="col">Incorrect A</th>
<th scope="col">Total A</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
JAVASCRIPT
function addRow(){
var rowcount = document.getElementById('rowcount').value;
var table = document.getElementById('tableAddResults');
for(y=0;y<rowcount;y++){
var newrow = table.insertRow();
var cell0 = newrow.insertCell(0);
var cell0Text = document.createTextNode('AT-');
cell0.appendChild(cell0Text);
cell0.setAttribute('contentEditable','true');
for(i=1;i<4;i++){
var cell = newrow.insertCell(i);
var cellText = document.createTextNode('');
cell.appendChild(cellText);
cell.setAttribute('contentEditable','true');
}
}
};
我使用的 CSS 代码如下。
div.container-fluid{
overflow:hidden;
overflow-y: scroll;
height: 450px;
}
【问题讨论】:
标签: javascript html css