代碼實現(xiàn)打印功能(asp.net+javascript)
更新時間:2009年05月08日 22:20:59 作者:
頁面實現(xiàn)打印的效果代碼,分為服務(wù)器端和客戶端單個即可,客戶端的比較不錯,本站也是類似的方法。
一.在服務(wù)器端實現(xiàn)
1.這個是在本頁面上的.cs文件里寫的
if (resultInt > 0)
{
//清除驗證碼 ,顯示執(zhí)行結(jié)果,并轉(zhuǎn)向新的地址
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()">
就可以了
二.在客戶端實現(xiàn)
<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-->打印地方的結(jié)尾
<a href="javascript:;" onclick="doPrint()">打 印 </a>
1.這個是在本頁面上的.cs文件里寫的
復(fù)制代碼 代碼如下:
if (resultInt > 0)
{
//清除驗證碼 ,顯示執(zhí)行結(jié)果,并轉(zhuǎn)向新的地址
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()">
就可以了
二.在客戶端實現(xiàn)
復(fù)制代碼 代碼如下:
<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-->打印地方的結(jié)尾
<a href="javascript:;" onclick="doPrint()">打 印 </a>
相關(guān)文章
JavaScript驗證用戶輸入的是字符或數(shù)字及ASCII Chart應(yīng)用
我們可以根據(jù)onkeydown事件的event.keyCode即是ASCII Chart來判斷字符或數(shù)字等,本文提供了相關(guān)鍵盤key對應(yīng)的ASCII碼,以供用戶使用是參考及使用onpaste事件只能輸入字符和數(shù)字防止粘貼等的,感興趣的朋友可以了解下2013-01-01asp.net sql 數(shù)據(jù)庫處理函數(shù)命令
asp.net sql 數(shù)據(jù)庫處理函數(shù)命令 ,需要的朋友可以參考下。2009-10-10c# 連接字符串?dāng)?shù)據(jù)庫服務(wù)器端口號 .net狀態(tài)服務(wù)器端口號
正常的數(shù)據(jù)庫連接字符串配置,這是在MSSQL服務(wù)器端口是1433(默認)的情況下。2009-06-06ASP.NET在底層類庫中獲取Session C#類中獲取Session
本文介紹一些在類庫中獲取Session、Page、Resposne、Request的方法和步驟,方便初學(xué)者使用。2016-03-03CheckBox控件默認選中,提交時永遠獲得選中狀態(tài)的實現(xiàn)代碼
下面小編就為大家?guī)硪黄狢heckBox控件默認選中,提交時永遠獲得選中狀態(tài)的實現(xiàn)代碼。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-05-05asp.net Cookie跨域、虛擬目錄等設(shè)置方法
Cookie跨域、虛擬目錄等設(shè)置方法,需要的朋友可以參考下。2009-11-11Visual Studio 2017開發(fā)環(huán)境的安裝圖文教程
Visual Studio 2017是微軟于2017年3月8日正式推出的新版本,是迄今為止 最具生產(chǎn)力 的 Visual Studio 版本。這篇文章主要介紹了Visual Studio 2017開發(fā)環(huán)境的安裝,需要的朋友可以參考下2017-11-11