打印按钮

head引用公共文件:
<!--#include file="../CUsing/printhead.asp" -->

body添加代码:
<input type="button" value="打印报表" onclick="preview(1)" />

<!--startprint1-->

正文

<!--endprint1-->

============================引用文件的内容===============
<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>

 

posted on 2020-03-07 23:03  sunyzone  阅读(258)  评论(0)    收藏  举报

导航