前端打印功能的实现

备忘,记录一下。

在需要打印页面生成一个div,ID为“Printing”;状态为display:none;使打印内容隐藏在该页面上,div里面的内容就是打印的内容根据需求填充即可。

然后给打印按钮加点击事件点击时调用该方法,一个简单打印功能就实现了。

function PrintArticle() { var pc = document.getElementById("Printing"); var pw = window.open('', '', 'width=1200,height=800'); pw.document.write('

'); pw.document.write(''); pw.document.write(''); pw.document.write(''); pw.document.write(''); pw.document.write(pc.innerHTML); pw.document.write(''); pw.document.write(''); pw.document.close(); pw.print(); return false; } $(".Printing").click(function () { PrintArticle() })

猜你喜欢

转载自www.cnblogs.com/fuxun/p/9258235.html