sal*_*lma 2 html javascript printing
我的打印html如下
<div id="DivIdToPrint" style="border:1px solid #000000;">
fdghgjhghjkjk
<div id="in">TO be are not to be that is the question</div>
</div>
Run Code Online (Sandbox Code Playgroud)
和javascript代码是:
function printDiv()
{
var divToPrint=document.getElementById('DivIdToPrint');
var newWin=window.open('','Print-Window','width=400,height=400,top=100,left=100');
newWin.document.open();
newWin.document.write('<html><body onload="window.print()">'+divToPrint.innerHTML+'</body></html>');
newWin.document.close();
setTimeout(function(){newWin.close();},10);
}
Run Code Online (Sandbox Code Playgroud)
我想打印"DivIdToPrint"div,但不显示"in"div内容.
正确的方法是使用@media print设置display:none
@media print {
.in {display:none}
}
Run Code Online (Sandbox Code Playgroud)
没有javascript!