web页面中如何打印指定的区域?
Posted On 2013年12月23日
一. 使用jquery, 自定义打印的内容, 并打印.
w=window.open();
w.document.write($('.report_left_inner').html());
w.print();
w.close();
二. 通过css的样式表进行指定. 但需要写div,将打印的区域包起来.
<head>
<style type="text/css"> #printable { display: none; } @media print { #non-printable { display: none; } #printable { display: block; } } </style>
</head> <body>
<div id="non-printable"> Your normal page contents </div>
<div id="printable"> Printer version </div>
</body>
三. 直接使用javascript 代码
<div id="printable"> <h1>Print me</h1> </div>
<input type="button" onclick="printDiv('printable')" value="print a div!" />
function printDiv(divName) { var printContents = document.getElementById(divName).innerHTML; var originalContents = document.body.innerHTML; document.body.innerHTML = printContents; window.print(); document.body.innerHTML = originalContents; }
此篇文章已被阅读2805 次