样式:
<style type="text/css" media="print">
@page
{
size: auto; /* auto is the initial value */
margin: 0mm; /* this affects the margin in the printer settings */
}
@media print {
thead {
display: table-header-group;},
tfoot {
display: table-footer-group;}
}
</style>
分页:
<iframe id="printIframe" src="" width="0" height="0" frameborder="0"></iframe>
<div id="printContent">
<p style="page-break-after: always"></p>
</div>
</iframe>
加载打印:
<script>
window.onload = function () {
print();
};
function print() {
let content = document.getElementById('printContent');
let printIframe = document.getElementById('printIframe');
printIframe.contentDocument.write(content.innerHTML);
printIframe.contentDocument.close();
printIframe.contentWindow.print();
}
</script>
打印数据
最新推荐文章于 2023-07-18 11:02:54 发布