从几个div打印文本

时间:2012-07-19 11:18:20

标签: jquery

我看到这个answer,但是如何继续从第二个,第三个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;
}

1 个答案:

答案 0 :(得分: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')" />