gpt4 book ai didi

javascript - 如何在每个打印页面上打印表格的标题?

转载 作者:太空宇宙 更新时间:2023-11-03 17:59:50 26 4
gpt4 key购买 nike

当我打印或打印预览时,我的表格包含大量动态行我只在第一页上使用 window.print() 函数获得表格 thead ..但我想要每个打印页面上的表格 thead ...帮助?

<div id="printablediv" >
<div style="padding:8px;font-size: 13px;">
<center>
<?php
$sumMul = 0;
$sumBil = 0;
?>
<?php $total = $total_ni = $total_aa = $total_pe = $total_bak = $total_cnt = 0; ?>
<table cellpadding="0" cellspacing="0" border="1" style="font-size: 13px;" >
<thead id="head">
<tr bgcolor="#333333" style="color:#black;font-weight: bold;">
<th width="100" align="center">Donor</th>
<th width="100" align="center">Loan No.</th>
<th width="120" align="center">Value Date</th>
<th width="90" align="center">Curr</th>
<th width="150" align="center">Multilateral</th>
<th width="150" align="center">Bilateral</th>
<th width="150" align="center">Forex</th>
<th width="150" align="center">Multilateral</th>
<th width="150" align="center">Bilateral</th>
</tr>
</thead>
<?php $previousValue = $list[0]->LOAN_ID; ?>
<?php $flag = 0; ?>
<?php foreach ($list as $key => $val): ?>
<tr>
<td align="center"><?php echo $val->EX_DONOR_CODE; ?></td>
<td align="center"><?php echo $val->LOAN_ID; ?></td>
<td align="center"><?php echo $val->VALUE_DATE; ?></td>
<td align="center"><?php echo $val->TRANSACTION_CURRENCY_CODE; ?></td>
<td align="right"><?php
if ($val->DONOR_TYPE == 'MULTILATERL') {
$sumMul += $val->COMMIT_CUR_AMT;
echo $val->COMMIT_CUR_AMT;
}
?></td>
<td align="right"><?php
if ($val->DONOR_TYPE == 'BILATERAL') {
$sumBil += $val->COMMIT_CUR_AMT;
echo $val->COMMIT_CUR_AMT;
}
?></td>
<td align="right"><?php //reports::report1_5Forex($val->TRANSACTION_CURRENCY_CODE ,$val->VALUE_DATE) ?></td>
<td align ="right"></td>
</tr>
<?php $previousValue = $val->LOAN_ID ?>

<?php endforeach; ?>
</table>
<input type="button" value="Print" id="prt" onclick="javascript:printDiv('printablediv')" />
</div>

我在这里得到了 javascript 代码:

<script language="javascript" type="text/javascript">
function printDiv(divID) {
var divElements = document.getElementById(divID).innerHTML;
var oldPage = document.body.innerHTML;
document.body.innerHTML =
"<body>" +
divElements + "</body>";
$('#prt').hide();
window.print();
$('#prt').show();
document.body.innerHTML = oldPage;
}

最佳答案

您应该使用theadtbody 在每页上打印表头http://www.w3.org/TR/html4/struct/tables.html#edef-THEAD

Table rows may be grouped into a table head, table foot, and one or more table body sections, using the THEAD, TFOOT and TBODY elements, respectively. This division enables user agents to support scrolling of table bodies independently of the table head and foot. When long tables are printed, the table head and foot information may be repeated on each page that contains table data.

如果这不起作用,则浏览器 vendor 没有正确实现标准。

关于javascript - 如何在每个打印页面上打印表格的标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25662967/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com