当前位置: 首页 > 图文教程 > 网络编程 > ASP > asp.net结合js的网页打印程序

ASP
ASP汉字转拼音,支持自定义特殊词语
终于找到了ASP下标越界的解决方法
ASP实现长文章手动分页的代码
如何节约程序开发中的时间
防sql注入代码
asp连接远程mssql数据库代码
fso检测文件、磁盘、文件夹是否存在代码
asp随机获取数据库中的记录代码
利用fso显示某一文件夹中的所有内容
利用asp获取客户端真实的IP地址
Cookies常用命令简介
将多行区域表单中的内容换成html代码
rs.open sql,conn,1,1中各参数的意义
动态图形验证码
常用的asp代码
ASP如何得到字符串的每一位字符
ASP用户登录代码
网站静态页面生成方法
fso生成有多行内容的html文件
fso向html文件追加内容

ASP 中的 asp.net结合js的网页打印程序


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 112 ::
收藏到网摘: n/a

循环打印div中的内容:

以下为引用的内容:

  <input type="button" onClick="javascript:printpage(’’myDiv’’);" value="打印"> 
流程: 
从数据库中取出记录-》放入aspx页面的一个Div中打印 
例子: 
在aspx中定义一个DIV,如: 
<div id="myDiv">   
     <table border="0"  width="100%"> 
         <tr> 
         <td> 
        <table align="center" border="0" cellpadding="5" cellspacing="1" 
            width="100%" class="test"> 
          <tr bgcolor="#CDD9F1" align="center"> 
            <td height="22" colspan="2" valign="middle">凭证</td> 
          </tr> 
        </table> 
         </td> 
    </tr> 
    </table> 
</div> 
在apsx中定义一个按钮,按下事件触发 
printpage(’’myDiv); 
Printpage方法如下(javascript): 
function printpage(myDiv){ 
   var newstr = document.all.item(myDiv).innerHTML; 
   var oldstr = document.body.innerHTML; 
   document.body.innerHTML = newstr; 
   window.print(); 
   document.body.innerHTML = oldstr; 
   return false; 
}  

===================================================
 
<script  language="JavaScript">  
var HKEY_Root,HKEY_Path,HKEY_Key; 
HKEY_Root="HKEY_CURRENT_USER"; 
HKEY_Path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"; 
//设置网页打印的页眉页脚为空 
function PageSetup_Null() 

 try 
 { 
         var Wsh=new ActiveXObject("WScript.Shell"); 
  HKEY_Key="header"; 
  Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,""); 
  HKEY_Key="footer"; 
  Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,""); 
 } 
 catch(e){} 


//设置网页打印的页眉页脚为默认值 
function  PageSetup_Default() 
{  
 try 
 { 
  var Wsh=new ActiveXObject("WScript.Shell"); 
  HKEY_Key="header"; 
  Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&w&b页码,&p/&P"); 
  HKEY_Key="footer"; 
  Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&u&b&d"); 
 } 
 catch(e){} 

</script> 
<input type="button" value="清空页码" onclick=PageSetup_Null()> 
<input type="button" value="恢复页码" onclick=PageSetup_Default()>