无法将格式传递给 javascript

Can't pass formatting to javascript

我有一个关于阅读网页然后打印弹出副本的问题。

基本上我在 A 页面上有一个表格。如果用户选择通过支票付款,他们的发票将在新的 window B 中弹出,这是一个打印预览。在 A 上找到的发票 table 格式正确。不幸的是,在弹出的打印页面 B 中,table 格式(实际上是所有页面格式)都消失了。即第一列居中,第二列右对齐,行底纹,table边框。

我正在考虑创建 3 个 div;一张之前,一张之后,一张包括 table 发票,但我所有的尝试都给出了格式错误的 table。然后我想我会在页面 A 中使用 div 重写,并重写弹出打印机页面以反映这一点(多个字符串被写为 strHeader、strTable、strFooter)。关于如何最好地进行的任何想法?

这是我的代码:

<script type="text/javascript">
function printContent(id){
str=document.getElementById(id).innerHTML
newwin=window.open('','printwin','left=100,top=100,width=1000%,height=1000%')
newwin.document.write('<HTML>\n<HEAD>\n')
newwin.document.write('<TITLE>Print Page</TITLE>\n')
newwin.document.write('<script>\n')
newwin.document.write('function chkstate(){\n')
newwin.document.write('if(document.readyState=="complete"){\n')
newwin.document.write('window.close()\n')
newwin.document.write('}\n')
newwin.document.write('else{\n')
newwin.document.write('setTimeout("chkstate()",2000)\n')
newwin.document.write('}\n')
newwin.document.write('}\n')
newwin.document.write('function print_win(){\n')
newwin.document.write('window.print();\n')
newwin.document.write('chkstate();\n')
newwin.document.write('}\n')
newwin.document.write('<\/script>\n')
newwin.document.write('</HEAD>\n')
newwin.document.write('<BODY onload="print_win()">\n')

newwin.document.write("<b><font size= '6' >" + 'Event Registration' + "   </font></b>")
newwin.document.write(str)
newwin.document.write('footer info goes here')

newwin.document.write('</BODY>\n')
newwin.document.write('</HTML>\n')
newwin.document.close()
}
</script>

<?php $this->set('title_for_layout', 'Event Registration Payment')?> 
<?php if($eventRegistration['EventRegistration']['payment_type'] =="cheque"):?>
<b>To pay by cheque...</b><a href="#null" onclick="printContent('print_div1')"> click here</a>
<?php endif;?>

<DIV id="print_div1" style="border:1px solid #000000">

<?php echo $this->Session->flash(); ?>
<?php echo $this->requestAction('/liveEditRegions/getRegion/60'); ?>

<table class="invoiceTable" style="margin-bottom: 10px;">
<tr class="titleRow">
<th class="center">Item</th>
<th class="center">Price</th>
</tr>

<!-------------------------------------registration-->
<?php if($registrationPrice > 0):?> 
<tr>
    <th class="center">Registration Price</th>
    <td class="right">$<?php echo number_format($registrationPrice, 2) ?></td>
</tr>
<?php endif;?>

<!-------------------------------------------events-->
<?php if($eventRegistration['EventRegistration']['dinner_ticket_number'] > 0):?> 
<tr>
    <th class="center">Dinner Ticket(s) x <?php echo     $eventRegistration['EventRegistration']['dinner_ticket_number']?> @ $<?php echo number_format($eventRegistration['EventRegistration']['dinner_ticket_price'])?></th>
    <td class="right">$<?php echo number_format($dinnerticketTotal, 2) ?></td>
</tr>
<?php endif;?> 

<?php if($eventRegistration['EventRegistration']['student_social_ticket_number'] > 0):?> 
<tr>
    <th class="center">Student Social Ticket(s) x <?php echo $eventRegistration['EventRegistration']['student_social_ticket_number']?> @ $<?php echo number_format($eventRegistration['EventRegistration']['student_social_ticket_price'])?></th>
    <td class="right">$<?php echo number_format($ssticketTotal, 2) ?></td>
</tr>
<?php endif;?> 

<tr>
<th class="right">Sub total</th>
<td class="right">$<?php echo number_format($subtotal, 2); ?></td>
</tr>
<tr>
<th class="right">TAX</th>
<td class="right">$<?php echo number_format($tax, 2); ?></td>
</tr>
<tr>
<th class="right">Total</th>
<td class="right">$<?php echo number_format($total, 2); ?></td>
</tr>
</table>

<!-----------------------------------------CHOOSE PAYMENT-->
<?php if($eventRegistration['EventRegistration']['payment_type'] =="credit card"):?>

[snip]

<?php endif;?>

<?php if($eventRegistration['EventRegistration']['payment_type'] =="cheque"):?>
<?php endif;?>
</DIV>

尝试查看是否有 css 样式表覆盖您的更改。可以在新页面上显式创建 table 样式以仔细检查。