js 打印

  直接调用打印: <a href="javascript:window.print();">打印</a>
提供打印,预览,设置等按钮:
<html>
<style   media="print">  
  .noprint   {   display:   none   }  
  </style>  
  </head>  
  <body>  
  <script   language="JavaScript">  
  function   doPrintSetup(){  
  //打印设置  
  WB.ExecWB(8,1)  
  }  
  function   doPrintPreview(){  
  //打印预览  
  WB.ExecWB(7,1)  
  }  
  function   doprint(){  
  //直接打印  
  WB.ExecWB(6,6)  
  }  
  </script>  
   
  <OBJECT   classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2   height=10   id=WB   width=10></OBJECT>
  <script >  
  function   window.onload()   {  
      //factory.printing.paperSize   =   "A3"  
      factory.printing.header   =   ""  
      factory.printing.footer   =   ""  
      factory.printing.portrait   =   false  
      idPrint1.disabled   =   false;   //   enable   UI   button  
      idPrint2.disabled   =   false;  
      idPrint3.disabled   =   false;  
      idPrint4.disabled   =   false;  
      factory.printing.leftMargin   =   0.75  
      factory.printing.topMargin   =   1.5  
      factory.printing.rightMargin   =   0.75  
      factory.printing.bottomMargin   =   1.5  
      }  
  </script>  
  <div   class=noprint>  
      <input   id="idPrint1"   type="button"   value="打印本页"  
    οnclick="doprint();">  
      <input   id="idPrint2"   type="button"   value="页面设置"  
    οnclick="doPrintSetup();">  
      <input   id="idPrint3"   type="button"   value="打印预览"  
    οnclick="doPrintPreview();">  
      <input   id="idPrint4"   type="button"  
    οnclick="window.close()"   value="关闭窗口">  
  </div>  
  <br/>  
  <table   width="720"   border="0"   cellspacing="0"   cellpadding="0"   align="center"   >  
      <tr>    
          <td     bgcolor="#0099ff"> 
                      放入要打印的内容
</td>  
  </tr></table></body>  </html>
要使用JavaScript进行打印,你可以使用以下代码: ```javascript function printPage(myDiv) { var printHtml = document.getElementById(myDiv).innerHTML; var printWindow = window.open('', '_blank'); printWindow.document.write('<html><head><title>Print</title></head><body>'); printWindow.document.write(printHtml); printWindow.document.write('</body></html>'); printWindow.document.close(); printWindow.print(); } ``` 在这个代码中,我们定义了一个名为`printPage`的函数,它接受一个参数`myDiv`,代表需要打印的元素的ID。使用`document.getElementById(myDiv).innerHTML`可以得到需要打印的元素的HTML内容。接下来,我们创建一个新窗口`printWindow`,并将需要打印的内容写入该窗口的文档中。最后,我们调用`printWindow.print()`来打印该窗口的内容。 请注意,为了确保打印的内容具有正确的样式,需要将样式以内联方式应用于需要打印的元素。这可以通过直接在元素上添加`style`属性来实现,或者使用CSS样式表并将其链接到打印窗口的文档中。 希望这个回答对你有帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [JavaScript 实现打印操作](https://blog.csdn.net/weixin_38168139/article/details/99760104)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值