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

ASP
asp利用dictionary创建二维数组
ASP + Serv-u 实现FTP的代码
asp获取数据库中所有表名和字段名
SITEMAP生成程序的ASP实现
通过XMLHTTP实现模板式静态页生成
实践xml缓存技术构建高性能web站点
一个简单好用的UBB编辑器(含代码)
使用ASP脚本命令重新启动服务器
技巧:用ASP在线创建Word与Excel文档
ASP.NET后台代码实现XmlHttp跨域访问
浅析 ASP.NET编程中的十大技巧
用ASP实现IE地址栏参数的判断
ASP调用SQL Server视图和存储过程
应用:用ASP实现在线文章翻译的功能
ASP实现无组件生成验证码-GIF格式
ASP实现长文章自动分页的函数代码
深入研究Application和Session对象
提高ASP的速度的方法:GetString
ASP进阶教程Ⅶ:留言簿设置密码验证
asp获取文件md5值

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 88 ::
收藏到网摘: 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()>