- 时间:2021-12-11 18:50 编辑: 来源: 阅读:
- 扫一扫,手机访问
摘要:代码实现打印功能(asp.net+javascript)
一.在服务器端实现
1.这个是在本页面上的.cs文件里写的
[url=printTKZ.aspx?type=BF&BMId=]"}" +
"else" +
"{" +
"window.location.href='buFeiList.aspx';" +
"}";
MessageBox.alert(Page, (object)caoCode);
}
2.在你想要的打印 printTKZ.aspx这个页面上写上
<body onload="vbscript:window.print()">
就可以了
二.在客户端实现
<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>
<!--startprint--> 放在打印地方的开头
<!--endprint-->打印地方的结尾
<a href="javascript:;" onclick="doPrint()">打 印 </a>