-3

我看到了这个答案,但是如何继续从第二个、第三个 div 打印文本?这就是我想要的:

<script type="text/javascript">
function PrintElem(elem)
{
    Popup($(elem).text());
}
function Popup(data) 
{
    var mywindow = window.open('', 'Coupon', 'height=300,width=710');
    mywindow.document.write('<html><head><title>Coupon</title>');
    /*optional stylesheet*/ mywindow.document.write('<link rel="stylesheet" href="cupon.css" type="text/css" />');
    mywindow.document.write('</head><body ><div class="coupon_logo"><img src="discount.jpg"></div><div class="coupon_conditions">');
             mywindow.document.write(data); // text from first div
    mywindow.document.write('</div>');
    mywindow.document.write('<div class="coupon_clinic_info">');
            //text from second div
    mywindow.document.write('</div>');
    mywindow.document.write('</body></html>');
    mywindow.print();
    mywindow.close();
    return true;
}

4

1 回答 1

2

我想只需将一个类应用于您要打印的所有 div 就可以了

<div id="mydiv" class="toprint">
    This will be printed. 
</div>

<div>
    This will not be printed.
</div>

<div id="anotherdiv" class="toprint">
    This will be printed.
</div>

然后使用您引用的问题的答案,更改此行:

<input type="button" value="Print Div" onclick="PrintElem('.toprint')" />
于 2012-07-19T11:23:27.810 回答