【发布时间】:2018-10-23 08:08:58
【问题描述】:
我试图让页脚仅在打印预览的页脚部分粘在最后一页的底部
页面内容是动态的,所以我不知道哪个是我的最后一页。
我已经尝试了下面的代码,它使页脚出现在预览的最后一页,但不在最后一页的页脚部分。目前页脚部分打印在第 2 页,它紧邻正文部分,但我希望在页脚部分的第 2 页打印页脚部分
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js"> </script>
<script language="javascript" type="text/javascript">
function printDiv(divID) {
//Get the HTML of div
var divElements = document.getElementById(divID).innerHTML;
//Get the HTML of whole page
var oldPage = document.body.innerHTML;
//Reset the page's HTML with div's HTML only
document.body.innerHTML =
"<html><head><title></title></head><body>" +
divElements + "</body>";
//Print Page
window.print();
//Restore orignal HTML
document.body.innerHTML = oldPage;
}
</script>
</head>
<body>
<button onclick="myFunction()"> Print this page</button> <input type="button" value="Print 1st Div" onclick="javascript:printDiv('printablediv')" /> >
<script>
function myFunction() {
window.print();
}
</script>
<div id="printablediv">
<table>
<thead>
<tr style="height:30px;"> <th> PAGE HEADER</th> </tr>
<thead>
<tfoot> <tr> <td id="spacer" style="height:200px;"> </td> </tr> </tfoot>
<tbody>
<tr>
<td>
content<br> content<br> content<br> content<br> content<br> content<br>
content<br> content<br> content<br> content<br> content<br> content<br>
content<br> content<br> content<br> content<br> content<br> content<br>
content<br> content<br> content<br> content<br> content<br> content<br>
content<br> content<br> content<br> content<br> content<br> content<br>
content<br> content<br> content<br> content<br> content<br> content<br>
content<br> content<br> content<br> content<br> content<br> content<br>
content<br> content<br> content<br> content<br> content<br> content<br>
</td>
</tr>
</tbody>
</table>
<div id="footer" style="position:relative; bottom: 0;"> Sample </div>
</div>
</body>
</html>
【问题讨论】:
-
将
position: relative;的footer更改为position: absolute;,应该可以。 -
@CodeF0x 感谢您的即时回复。根据您的建议,我们厌倦了将位置更改为绝对位置,但页脚部分未显示在第 2 页中,但显示在第 1 页中
-
@Pradeep 你解决了这个问题吗?如果您有解决此问题的方法,请分享,谢谢
-
你找到解决办法了吗?
标签: javascript html css google-chrome print-preview