gpt4 book ai didi

javascript - 在 Javascript 中将表格打印为两部分

转载 作者:行者123 更新时间:2023-12-02 20:13:52 25 4
gpt4 key购买 nike

我应该打印一个表格,但表格不适合纸张。我必须打印为两部分。我该怎么办?

请帮助我。

最佳答案

使用THEAD, TFOOT, and TBODY elements可以解决问题而不需要javascript。以下是 W3C 文档中的引用:

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. When long tables are printed, the table head and foot information may be repeated on each page that contains table data.

请注意,如果包含,tfoot 必须位于 tbody 之前:

<table>
<thead>
<tr>
<th>Col 1 heading</th>
<th>Col 2 heading</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Col 1 footer</th>
<th>Col 2 footer</th>
</tr>
</tfoot>
<tbody>
<tr>
<td>Col 1 data</td>
<td>Col 2 data</td>
</tr>
<tr>
<td>Col 1 data</td>
<td>Col 2 data</td>
</tr>
</tbody>
</table>

打印表格时,thead 中的行应在每页表格的顶部重复。同样,打印表格时,tfoot 中的行(如果包含)应打印在每页表格的底部。这取决于用户代理(例如浏览器)来执行此操作,但我认为大多数现代浏览器都能正确处理此问题 - 但这不是我测试过的东西。我很想知道你过得怎么样。

关于javascript - 在 Javascript 中将表格打印为两部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6606850/

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