html打印表格每頁都有的表頭和打印分頁


本文轉載:http://www.cnblogs.com/RitchieChen/archive/2008/07/30/1256829.html

 在做項目的時候碰到的。用戶要求,頁面呈現太長時,打印的時候,要求,每頁上都要有表頭。找了好久,才在網上找到。原來,是要對每個表格,定義其thead,並對其樣式設置成:style="display:table-header-group"。如果要求有表尾,也一樣,要定義其tfoot,並對style="display:table-footer-group"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>無標題文檔</title>
<style>
@media print{
INPUT {display:none}
}
</style>
</head>

<body>

<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>
<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=javascript:window.print()>
</body>
</html>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM