我在 php 中有一个 foreach 循环。现在我需要分别为每条记录打印一个 div 的内容,我现在拥有的内容如下:
<script type="text/javascript">
function printContent(div_id) {
var DocumentContainer = document.getElementById("<?php echo $route->flightnum;?>");
var html = '<html><head>' +
'</head><body style="background:#ffffff;">' + DocumentContainer.innerHTML +
'</body></html>';
var WindowObject = window.open("", "PrintWindow", "width=1000,height=1000,top=0,left=0,toolbars=no,scrollbars=yes,status=no,resizable=yes");
WindowObject.document.writeln(html);
WindowObject.document.close();
WindowObject.focus();
WindowObject.print();
//WindowObject.close();
document.getElementById('print_link').style.display = 'block';
}
</script>
然后我有以下div:
<div id="brief_print" style="margin-left: 15px">
.
.
.
.
.
</div>
也许是这样的链接:
<a class="glow" style="text-decoration: underline;" href="javascript:printContent('<?php echo $route->flightnum;?>')"id='print_link'>Open in new window for printing</a>
我的问题是,当我点击链接时,我没有得到任何回报。请告诉我哪里错了。谢谢
整个代码:
<?php
foreach($allroutes as $route)
{
?>
<tr>
<td onclick="$('#details_<?php echo $route->flightnum;?>').toggle('slow')">P</td>
<td style="padding:5px 10px" ALIGN="center"><?php echo $route->depicao;?></td>
<td style="padding:5px 10px" ALIGN="center"><?php echo $route->arricao;?></td>
<td style="padding:5px 10px" ALIGN="center"><?php echo $route->aircraft; ?></td>
<td style="padding:5px 10px"ALIGN="center"><?php echo $route->distance;?></td>
</tr>
<tr >
<td colspan="14"><div align="center">
<table cellspacing="0" width="100%" id="details_<?php echo $route->flightnum;?>" style="display:none">
<tr><th style="padding:5px 10px"><div align="center">Flight Details</div></th></tr>
<tr><td>
<section>
<?php
if(!isset($_GET['newwindow']))
{
?>
<a class="glow" style="text-decoration: underline;" href="javascript:printContent('<?php echo $route->flightnum;?>')"id='print_link'>Open in new window for printing</a>
<script type="text/javascript">
function printContent(div_id)
{
var DocumentContainer = document.getElementById("<?php echo $route->flightnum;?>");
var html = '<html><head>'+'</head><body style="background:#ffffff;">'+ DocumentContainer.innerHTML+ '</body></html>';
var WindowObject = window.open("", "PrintWindow","width=1000,height=1000,top=0,left=0,toolbars=no,scrollbars=yes,status=no,resizable=yes");
WindowObject.document.writeln(html);
WindowObject.document.close();
WindowObject.focus();
WindowObject.print();
//WindowObject.close();
document.getElementById('print_link').style.display='block';
}
</script>
<?php
}
?>
<div id="brief_print" style="margin-left: 15px">
<pre>
<b>Departing</b> : <?php echo $schedule->depname ?>
<b>Arriving</b> : <?php echo $schedule->arrname ?>
<b>Equipment</b> : <?php echo $schedule->fullname;?>
<b>Alternate</b> : <?php echo $alternate1; ?>
<b>Alternate</b> : <?php echo $alternate2; ?>
<b>Alternate</b> : <?php echo $alternate3; ?>
</pre>
</div>
</section>
</td></tr>
</table>
</div>
<?php
}
?>