一般是通过 media=“print” 样式表进行格式化:对<style media="print">、<link media="print">
的用法合理应用,但是media="print"是不被网页所显示的,只能在打印的效果上存在,这样就可以设置出打印效果和在网页上所显示的不一样。
eg:
在原页面显示,打印时不显示:noprint
在原页面不显示,打印时显示:_print
<style>
._print{display:none;}
</style>
<style media="print">
@page {
size: auto; /* auto is the initial value */
margin: 0mm 10mm; /* this affects the margin in the printer settings */
}
.noprint{display: none;}/* 在打印时隐藏 */
._print{display:block;}/* 在打印时显示 */
</style>
注意点:切记<style>
要写在<style media="print">
前才生效
补充:打印
1)可以用引入iframe框架的方法
<iframe src="reportOverviewPrint.html" style="width:100%; min-width: 900px;height:700px;" runat="server" frameborder="no" border="0" scrolling="no" allowtransparency="yes" id="printId"></iframe>
把需要打印的界面写入reportOverviewPrint.html,不需要打印的部分写在原html即可
2)引用jQuery.print.js
jQuery简单易用的网页内容打印插件jQuery.print