的
我正在尝试使用HTML打印页面的页脚。但是,我只需要页脚从第二页开始。将生成的页数因文档而异。到目前为止,它要么显示在每个页面中,要么显示在页面末尾。
JavaScript:
if (lineNo > 35) {
content += "<div id='print-footer' width=100%>";
content += "<table cellspacing=0 cellpadding=0 width=100% border=0>";
content += "<tr><td style='font-family: Times New Roman; font-size:12px;'>Ref No.: " + tranId + "</td></tr>";
content += "</table>";
content += "</div>";
}
.HTML:
<style type="text/css" media="print">
div#print-footer {
position: fixed;
right: 14px;
bottom: 0;
background-color: white
}
</style>
隐藏第一页上的页脚
div#print-footer:nth-of-type(1) {
... css for hiding the footer
}
顺便说一句,您不应该使用id='print-footer'
因为它看起来存在不止一次。使用class='print-footer'
并将#
替换为 css 中的点.
编辑:添加另一个变量来跟踪页面。如果需要,您也可以将其用作页码。
创建用于打印的全局
pageNo = 1;
并省略第一页的页脚
if (lineNo > 35) {
if (pageNo > 1) {
content += "<div id='print-footer' width=100%>";
content += "<table cellspacing=0 cellpadding=0 width=100% border=0>";
content += "<tr><td style='font-family: Times New Roman; font-size:12px;'>Ref No.: " + tranId + "</td></tr>";
content += "</table>";
content += "</div>";
}
pageNo++;
}
编辑2:
对于第一个解决方案,此jsfiddle中的简单示例,以查看第一个print-footer
是如何隐藏