页面打印

来源:互联网 发布:linux如何设置ip 编辑:程序博客网 时间:2024/05/19 18:43

<html>
<head>
<style>
@media print{
INPUT {display:none}
}
</style>
<TABLE border="0" style="font-size:9pt;" width="300px" align="center">
<THEAD style="display:table-header-group;font-weight:bold">
<TR><TD colspan="2" align="center" style="font-weight:bold;border:3px double red">每页都有的表头</TD></TR>
</THEAD>
<TBODY style="text-align:center"">
<TR><TD>表格内容</TD><TD>表格内容</TD></TR>
<TR><TD>表格内容</TD><TD>表格内容</TD></TR>
<TR><TD>表格内容</TD><TD>表格内容</TD></TR>
<TR><TD>表格内容</TD><TD>表格内容</TD></TR>
<TR><TD>表格内容</TD><TD>表格内容</TD></TR>
<TR><TD>表格内容</TD><TD>表格内容</TD></TR>
<TR style="page-break-after:always;"><TD>表格内容
</TD><TD>表格内容</TD></TR>
<TR><TD>表格内容</TD><TD>表格内容</TD></TR>
<TR><TD>表格内容</TD><TD>表格内容</TD></TR>
<TR><TD>表格内容</TD><TD>表格内容</TD></TR>
<TR><TD>表格内容</TD><TD>表格内容</TD></TR>
<TR><TD>表格内容</TD><TD>表格内容</TD></TR>
<TR><TD>表格内容</TD><TD>表格内容</TD></TR>
<TR style="page-break-after:always;"><TD>表格内容</TD><TD>表格内容</TD></TR>
</TBODY>
<TFOOT style="display:table-footer-group;font-weight:bold">
<TR>
<TD colspan="2" align="center" style="font-weight:bold;border:3px double blue">每页都有的表尾</TD>
</TR>
</TFOOT>
</TABLE>
<input type=button value=" 打 印 " onclick="window.print()">
</html>

 

 

 

(2)

       

1.添加以下css:
<style type="text/css" media="print">
.table1 {border-collapse:collapse;}
.thead1 {display:table-header-group;}
.thead1 td{text-align:center;font-weight:bold;border-top:1px solid #999999;padding:2px;}
.tbody1 {text-align:center;}
.tfoot1 {display:table-footer-group;}
.tfoot1 td{ margin-top:5px;}
.page_break_after {page-break-after:always;}
</style>
2.在table中添加thead、tbody、tfoot,然后用class引用上面的css;
3.在循环中判断每页打印多少条,如果当前页达到要打印的条数tr就加上class="page_break_after"(<tr class="page_break_after">),否则就不加。

                 

原创粉丝点击