代码实现打印功能(asp.net+javascript)
更新时间:2009年05月08日 22:20:59 作者:
页面实现打印的效果代码,分为服务器端和客户端单个即可,客户端的比较不错,本站也是类似的方法。
一.在服务器端实现
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>
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);
}
<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>
相关文章
JavaScript验证用户输入的是字符或数字及ASCII Chart应用
我们可以根据onkeydown事件的event.keyCode即是ASCII Chart来判断字符或数字等,本文提供了相关键盘key对应的ASCII码,以供用户使用是参考及使用onpaste事件只能输入字符和数字防止粘贴等的,感兴趣的朋友可以了解下2013-01-01c# 连接字符串数据库服务器端口号 .net状态服务器端口号
正常的数据库连接字符串配置,这是在MSSQL服务器端口是1433(默认)的情况下。2009-06-06ASP.NET在底层类库中获取Session C#类中获取Session
本文介绍一些在类库中获取Session、Page、Resposne、Request的方法和步骤,方便初学者使用。2016-03-03CheckBox控件默认选中,提交时永远获得选中状态的实现代码
下面小编就为大家带来一篇CheckBox控件默认选中,提交时永远获得选中状态的实现代码。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2016-05-05
最新评论