问题是这样的:WEB页面有多个DIV,按照业务需求,我只需要打印其中一个DIV里的内容,各位JS前辈,有好的解决方法吗?

解决方案 »

  1.   

    和lodop打印控件吧,很好用,而且是免费的,我最近弄个项目要打印也是用的这控件
      

  2.   

    <HTML>
    <HEAD>
    <TITLE>Test Printer</TITLE><script language=javascript>///////////////////////BGN::printer language::BGN///////////////////////
    function SetPrintSettings()
    {//控制"纵打、 横打、页面的边距"。    // -- advanced features
        factory.printing.SetMarginMeasure(2)  // measure margins in inches
        factory.SetPageRange(false, 1, 3)    // need pages from 1 to 3    factory.printing.printer      = "Panasonic KX-P1121"
        factory.printing.copies       = 2
        factory.printing.collate      = true
        factory.printing.paperSize    = "A4"
        factory.printing.paperSource  = "Manual feed"    // -- basic features
        factory.printing.header       = false
        factory.printing.footer       = false
        factory.printing.portrait     = false
        factory.printing.leftMargin   = 1.0
        factory.printing.topMargin    = 1.0
        factory.printing.rightMargin  = 1.0
        factory.printing.bottomMargin = 1.0
    }function printsetup()
    {// 打印页面设置
         wb.ExecWB(8,1);
    }
    function printpreview()
    {// 打印页面预览
        t.style.display='none';
        wb.ExecWB(7,1);
        t.style.display='block';
    }function printExec()
    {//开始打印
        wb.ExecWB(6,6)
    }function beginPrint()
    {
       t.style.display='none';
       printExec();
       t.style.display='block';
    }function freshWin()
    {
      wb.ExecWB(22,1);
    }function closeWin()
    {
      //window.opener=null;
      window.close();
    }///////////////////////BGN::printer language::BGN///////////////////////
    </script></HEAD>
    <STYLE>
    <!--
    A:link {text-decoration:none; color:black;}
    A:visited {text-decoration:none; color:black;}
    A:hover {  text-decoration:none;  color:brown;}
    p,br,body,td,table,tr {color:black; font-size:9pt;}
    -->
    </STYLE><BODY style="margin:0">
    <TABLE WIDTH='100%' CELLSPACING=1 CELLPADDING=1 BORDER=0>
    <TR BGCOLOR='#D6D39C' HEIGHT=23 ALIGN=CENTER>
    <TD>产品编号</TD>
    <TD>购买商品</TD>
    <TD>供货商</TD>
    <TD>价格</TD>
    <TD>数量</TD>
    <TD>合计/分数</TD>
    <td>修改</td>
    </TR>
    </table><p>大大大大大大大大大大大大大大大大大大在</p><!------------------------------------BGN::隐藏的打印层---------------------------------------------->
    <!------------------------------------BGN::隐藏的打印层---------------------------------------------->
    <!------------------------------------BGN::隐藏的打印层----------------------------------------------><!------------------------------------BEGIN::打印功能控件-------------------------------------------->  <OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"  height=0 id=wb name=wb width=0>
      </OBJECT>
      <!------------------------------------END  ::打印功能控件--------------------------------------------><center>
    <div  id='t'  style='cneter' >
    <br>
    <input type=button  name=button_print value="开始打印"   onclick="beginPrint()">
    <input type=button  name=button_setup value="页面设置"   onclick="printsetup();">
    <input type=button  name=button_show  value="打印预览"   onclick="printpreview();">
    <input type=button  name=button_fh    value="刷新本页"   onclick="freshWin()">
    <input type=button onClick="closeWin()"  value="关  闭">
    <br>
    </div>
    </center>
    <!------------------------------------END::隐藏的打印层---------------------------------------------->
    <!------------------------------------END::隐藏的打印层---------------------------------------------->
    <!------------------------------------END::隐藏的打印层----------------------------------------------></BODY>
    </HTML>