zoukankan      html  css  js  c++  java
  • js完成打印功能

    最近在做项目要求实现打印功能,我采用js方式来实现

    window.print();会弹出打印对话框,打印的是window.docunemt.body.innerHTML中的内容,可以局部打印,也可以全局打印.

    <!DOCTYPE html>  
    <html>  
    <head>  
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
    <title>局部打印案例</title>  
    <script type="text/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>  
    </head>  
      
    <body>  
    <p>不需要打印的地方</p>  
    
    <!--startprint--><!--注意要加上html里star和end的这两个标记-->  
    <h1>打印标题</h1>  
    <p>打印内容~~</p>  
    <!--endprint-->  
    <button type="button" onclick="doPrint()">打印</button>  
    <p>不打印的地方</p>  
    </body>  
    </html>  
  • 相关阅读:
    EnumMap实现类
    java enum
    openssl生成RSA公钥和私钥对
    rsa 公钥 私钥
    eclispe 通过git向码云上传
    eclipse git 报 git: 401 Unauthorized
    HttpClient 超时时间
    HttpClient 4 和 HttpClient 3 超时
    Java RSA 生成公钥 私钥
    万能适配器
  • 原文地址:https://www.cnblogs.com/FanJava/p/8512520.html
Copyright © 2011-2022 走看看