- 首先创建一个iframe
<iframe src="" frameborder="0" id="printf" width="0" height="0"></iframe>
- 创建打印函数
_printPage = () => {
let f = document.getElementById('printf');
let printHTML = "";
printHTML = "<div>要打印的内容</div>"; //构造要打印的HTML内容
f.contentDocument.write(printHTML);
f.contentDocument.close();
f.contentWindow.print();
}
网友评论