前端局部打印

先将需要打印的内容添加id=print
const el =documnet.getElementById('printRoute').innerHTML;
const iframe =document.createElement('IFRAME');
let doc=null;
document.body.appendChild(iframe);
doc =iframe.contentWindow.document;
doc.write(el);
doc.close();
iframe.contentWindow.focus();
iframe.contentWindow.print();
document.body.removeChild(iframe);

posted @ 2021-08-20 10:50  learning豪  阅读(116)  评论(0编辑  收藏  举报