当前位置: 移动技术网 > IT编程>开发语言>.net > 代码实现打印功能(asp.net+javascript)

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

尧都二手房出售,上海商铺转让,老男孩solo吉他谱

一.在服务器端实现
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>

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网