js调用打印机

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
       <input id="btnPrint" value="打印" type="button" onclick="preview()";/>  
        
        <!--startprint-->
       <table border="1" cellspacing="0" cellpadding="0">
               <tr>
                   <td>111111</td>
                   <td>222222</td>
               </tr>
               <tr>
                   <td>111111</td>
                   <td>222222</td>
               </tr>
               <tr>
                   <td>111111</td>
                   <td>222222</td>
               </tr>
       </table>
       <!--endprint-->

</body>
</html>
<script type="text/javascript">function preview()    
    {    
        bdhtml=window.document.body.innerHTML;    
        //<!--startprint-->开始标志
        sprnstr="<!--startprint-->";   
        // <!--endprint-->结束标志
        eprnstr="<!--endprint-->";    
        prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+17);    
        prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));    
        window.document.body.innerHTML=prnhtml;    
        window.print();    
    }
</script>

 

posted @ 2017-11-23 16:57  波罗斯の程序日记  阅读(495)  评论(0编辑  收藏  举报