欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

代码实现打印功能(asp.net+javascript)

程序员文章站 2024-03-09 13:31:29
一.在服务器端实现 1.这个是在本页面上的.cs文件里写的 复制代码 代码如下:if (resultint > 0) { //清除验证码 ,显示执行结果,并转向新的地...
一.在服务器端实现
1.这个是在本页面上的.cs文件里写的
复制代码 代码如下:

if (resultint > 0)
{
//清除验证码 ,显示执行结果,并转向新的地址
session["yanzhengma"] = "";
string caocode = "if(confirm('提交成功,是否打印'))" +
"{" +
"window.location.href='printtkz.aspx?type=bf&bmid=" + _flowidvalue +"&bufeitime="+ _jftimevalue +"&palje=" +_shouxianvalue + "&goto=bufeilist.aspx';" +
"}" +
"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>