代碼實(shí)現(xiàn)打印功能(asp.net+javascript)
更新時(shí)間:2009年05月08日 22:20:59 作者:
頁面實(shí)現(xiàn)打印的效果代碼,分為服務(wù)器端和客戶端單個(gè)即可,客戶端的比較不錯(cuò),本站也是類似的方法。
一.在服務(wù)器端實(shí)現(xiàn)
1.這個(gè)是在本頁面上的.cs文件里寫的
if (resultInt > 0)
{
//清除驗(yàn)證碼 ,顯示執(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這個(gè)頁面上寫上
<body onload="vbscript:window.print()">
就可以了
二.在客戶端實(shí)現(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.這個(gè)是在本頁面上的.cs文件里寫的
復(fù)制代碼 代碼如下:
if (resultInt > 0)
{
//清除驗(yàn)證碼 ,顯示執(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()">
就可以了
二.在客戶端實(shí)現(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)文章
JQuery為用戶控件(ASCX)賦值與接口的應(yīng)用
在網(wǎng)頁動(dòng)態(tài)加載用戶控件,并使用JQuery為來把網(wǎng)頁處理的值傳給用戶控件,此文利用了接口方面的知識(shí),感興趣的各位可以參考下哈2013-03-03
ASP.NET預(yù)備知識(shí)學(xué)習(xí)筆記
這篇文章主要介紹了ASP.NET預(yù)備知識(shí),內(nèi)容很全面,幾乎涵蓋了asp.net預(yù)備知識(shí)點(diǎn),感興趣的小朋友可以看一看。2015-09-09
ASP.NET core Web中使用appsettings.json配置文件的方法
這篇文章主要給大家介紹了在ASP.NET core Web中使用appsettings.json配置文件的方法,文中給出了詳細(xì)的示例代碼,需要的朋友可以參考學(xué)習(xí),下面來一起看看吧。2017-04-04
google suggest 下拉菜單實(shí)現(xiàn)代碼(asp.net版本)
原來發(fā)表過,是asp版本的,但是不支持上下鍵,現(xiàn)在后臺(tái)處理程序用.net寫的。代碼進(jìn)行部分優(yōu)化。2009-07-07
ASP.NET Core通用主機(jī)實(shí)現(xiàn)托管服務(wù)
這篇文章介紹了ASP.NET Core通用主機(jī)實(shí)現(xiàn)托管服務(wù)的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-07-07

