首页 > Web开发 > 详细

js打印

时间:2020-04-25 10:49:20      阅读:41      评论:0      收藏:0      [点我收藏+]

<!DOCTYPE html>
<html>
<head>
<metahttp-equiv ="Content-Type" content="text/html;charset=utf-8" />
<title></title>
<metacharset ="utf-8" />
<script language="javascript">
function preview(oper) {
if (oper < 10) {
bdhtml = window.document.body.innerHTML;//获取当前页的html代码
sprnstr = "<!--startprint" + oper + "-->";//设置打印开始区域
eprnstr = "<!--endprint" + oper + "-->";//设置打印结束区域
prnhtml = bdhtml.substring(bdhtml.indexOf(sprnstr) + 18); //从开始代码向后取html
prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));//从结束代码向前取html
window.document.body.innerHTML = prnhtml;
window.print();
window.document.body.innerHTML = bdhtml;
} else {
window.print();
}
}
</script>
</head>
<body>
<!--startprint1-->
<table>
<tr><th>bb</th><th>cc</th></tr>
<tr><th>1</th><th>男</th></tr>
<tr><th>2</th><th>女</th></tr>
</table>
<input type="button" name=‘button_export‘ title=‘打印1‘ onclick="preview(1)" value="打印1" />


<table>
<tr><th>编号</th><th>性别</th></tr>
<tr><th>1</th><th>男</th></tr>
<tr><th>2</th><th>女</th></tr>
</table>

<input type="button" name=‘button_export‘ title=‘打印1‘ onclick="preview(1)" value="打印1" />
<!--endprint1-->
</body>

</html>

js打印

原文:https://www.cnblogs.com/ljx111/p/12771549.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!