JavaScript
<script type="text/javascript">
function printDiv() {
var printContent1 = document.getElementById('divMail1');
var printContent2 = document.getElementById('divMail2');
var newWin = window.open('', 'PrintWindow', 'width=800,height=530,top=10,left=100,scrollbars=1,resizable=yes');
newWin.document.open();
newWin.document.write('<html/><body onload="window.print()">' + printContent1.innerHTML + '</body></html>');
newWin.document.close();
}
</script>
HTML
<div id="divMail1">
<div>
<img src="image1.jpg"/>
</div>
<div>
<img src="image2.jpg"/>
</div>
<div id="divMail2">
<div>
<img src="image3.jpg"/>
</div>
<div>
<img src="image4.jpg"/>
</div>
</div>
<input type="button" value="Print" onclick="printDiv()"/>
嗨,我想在打印预览中显示一个 div(divMail1) 并打印另一个 div(divMail2)。可能吗。请帮我。