gpt4 book ai didi

javascript - 如何独立于 "tbody"滚动表的 "thead"?

转载 作者:IT王子 更新时间:2023-10-29 02:56:25 27 4
gpt4 key购买 nike

W3 specification 中所述对于表:

Table rows may be grouped into a table head, table foot, and one or more table body sections, using the THEAD, TFOOT and TBODY elements, respectively. This division enables user agents to support scrolling of table bodies independently of the table head and foot.

我创建了 following example , 但它不起作用。

HTML:

<table>
<thead>
<tr>
<td>Problem</td>
<td>Solution</td>
</tr>
</thead>
<tbody>
</tbody>
</table>

JS:

$(function() {
for (var i = 0; i < 20; i++) {
var a = Math.floor(10 * Math.random());
var b = Math.floor(10 * Math.random());
var row = $("<tr>").append($("<td>").html(a + " + " + b + " ="))
.append($("<td>").html(a + b));
$("tbody").append(row);
}
});

CSS:

table {
background-color: #aaa;
}
tbody {
background-color: #ddd;
height: 100px;
overflow: auto;
}
td {
padding: 3px 10px;
}

最佳答案

缺少的部分是:

thead, tbody {
display: block;
}

Demo

关于javascript - 如何独立于 "tbody"滚动表的 "thead"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8321849/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com