JavaScript 页面打印
时间:2019-08-20 13:50:44 来源:igfitidea点击:
JavaScript使用window对象的print函数可以实现打印当前页面的内容。
print()方法将打开打印对话框,让用户选择首选打印选项。
JS 页面打印示例
<html>
<head>
</head>
<body>
页面内容
<form>
<input type = "button" value = "打印当前页面" onclick = "window.print()" />
</form>
</body>
<html>
使用js库打印文档
我们还可以使用一些js库来打印文档。 比如 print.js 下载地址 https://printjs.crabbly.com
使用js打印pdf
<button type="button" onclick="printJS('docs/printjs.pdf')">
Print PDF
</button>
使用js打印html
<form method="post" action="#" id="printJS-form">
...
</form>
<button type="button" onclick="printJS('printJS-form', 'html')">
Print Form
</button>

