表单打印的2种方式

一、支持不同的浏览器

1、表单打印功能调用window.print() 就可以打印了

2、如果只打印表单上的一部分样式,将不想打印的部分写在@media print中,隐藏掉

<style>
  @media print{
    .Noprint{
      display:none;
    }
  }
</style>

3、如果还想实现打印预览的话,如下写法:

  var newWin = "print";
  window.open("./11.html",newWin,'location=no,menubar=no,toolbar=no,status=no,directories=no,scrollbars=yes,resizable=yes,width=700 height=500');
  frmMain.target = newWin;
  frmMain.submit();

 我的理解是将当前表单重新提交到一个新的窗口上即可

 

二、只支持IE浏览器 

<style media="print">
        .Noprint
        {
            display: none;
        }
</style>
<center class="Noprint">
     <object id="WebBrowser" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0" width="0"> </object>
     <input type="button" value="打印" onclick="document.all.WebBrowser.ExecWB(6,1)">
     <input type="button" value="直接打印" onclick="document.all.WebBrowser.ExecWB(6,6)">
     <input type="button" value="页面设置" onclick="document.all.WebBrowser.ExecWB(8,1)">
     <input type="button" value="打印预览" onclick="document.all.WebBrowser.ExecWB(7,1)">
 </center>

 

posted on 2017-05-25 19:46  hello策  阅读(2028)  评论(0编辑  收藏  举报