web页面调用js打印

这里打印的是这两个标签之间的内容。主要是,调用window.print();进行打印

<html>
<script language=javascript>
function doPrint() { 
bdhtml=window.document.body.innerHTML; 
sprnstr="<!--startprint-->"; 
eprnstr="<!--endprint-->"; 
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17); 
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr)); 
window.document.body.innerHTML=prnhtml; 
window.print();

}
</script>
<body>
<h1>sdsdsd</h1>
<!--startprint-->
	这是个测试哦。
<!--endprint-->
<a href="javascript:;" onClick="doPrint()">打印</a>
</body>
</html>

发表评论

This site uses Akismet to reduce spam. Learn how your comment data is processed.

关闭菜单