Javascript 打印表格显示文本页眉和页脚

Javascript 打印表格显示文本页眉和页脚,javascript,html,css,printing,Javascript,Html,Css,Printing,当我在html上打印数据表时,我遇到了如何添加文本页眉和页脚的问题。我已经在标题上添加了标题,但我的模板上的默认javascript似乎识别了没有样式的,我看不出它是否与您试图实现的目标完全匹配,但您可以稍后检查样式 thead标记的基本结构应该如下所示: <thead> <tr> <th colspan=9>This should display on print</th> </tr> <tr>

当我在html上打印数据表时,我遇到了如何添加文本页眉和页脚的问题。我已经在标题上添加了标题,但我的模板上的默认javascript似乎识别了没有样式的,我看不出它是否与您试图实现的目标完全匹配,但您可以稍后检查样式

thead
标记的基本结构应该如下所示:

<thead>
  <tr>
    <th colspan=9>This should display on print</th>
  </tr>
  <tr>
    <th>ID Number</th>
    <th>Name</th>
    <th>Barangay</th>
    <th>Sex</th>
    <th>Sector</th>
    <th>Amount</th>
    <th>Signature/thumb</th>
    <th >ID &nbsp;&nbsp;</th>
    <th>Date Received</th>
  </tr>
</thead>
<tfoot>
  <tr>
    <td colspan=9>Text for the footer goes here</td>
  </tr>
</tfoot>

这应该在打印时显示
身份证号码
名称
巴郎涯
性
部门
数量
签名/拇指
身份证件
收到日期
页脚的文本显示在此处
在表中有9列,因此title
th
标记需要跨越所有9列。这是通过将
colspan=9
添加到
th
元素本身来实现的

应该以类似的方式添加页脚。请注意,
t必须在
thead
之后和任何
tbody
标记之前立即输入
t foot


(更新为包含
tfoot

根据设计,
表格
对象的
thead
tfoot
部分应在表格出现的每一页上打印出来。看起来您已经有了一个
thead
部分来显示列标题。您只需在上面添加一行
tr
,然后使用
colspan
用一个
th
标记覆盖所有列-这将包含您的标题。@ATD感谢您的回复,我添加了上面的表,但您能帮我在哪里添加colspan吗?关于tr?谢谢好主意,我已经用过了,但是你知道为什么打印时标题页眉和页脚会在每页上重复吗?我只想在页面顶部显示标题,在打印页面的末尾显示页脚。感谢您的回复,请查看我在fiddle中更新的代码,我无法使用该功能打印。我已经将代码复制到一个新的HTML文件中,该文件的打印预览实现了我所期望的功能。标题打印在第一页的表格顶部和第二页显示的表格部分的顶部。页脚显示在第一页的表格底部和第二页的表格末尾。您不想打印哪一位?谢谢您的回复我已经更新了上面的html,我想打印我表格的所有数据,但我想打印第一页顶部的页眉标题和最后一页的页脚。当前,打印时,页眉和页脚上方的代码会显示每页的页眉和页脚,但是,是否希望页眉在每页上重复?谢谢您的回答,不,我只想在第一页打印页眉,页脚只打印最后一页请帮助
<thead>
  <tr>
    <th colspan=9>This should display on print</th>
  </tr>
  <tr>
    <th>ID Number</th>
    <th>Name</th>
    <th>Barangay</th>
    <th>Sex</th>
    <th>Sector</th>
    <th>Amount</th>
    <th>Signature/thumb</th>
    <th >ID &nbsp;&nbsp;</th>
    <th>Date Received</th>
  </tr>
</thead>
<tfoot>
  <tr>
    <td colspan=9>Text for the footer goes here</td>
  </tr>
</tfoot>