gpt4 book ai didi

javascript - 无法将格式传递给 JavaScript

转载 作者:行者123 更新时间:2023-12-03 10:18:45 26 4
gpt4 key购买 nike

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

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

我正在考虑创建 3 个 div;一张之前,一张之后,一张包括表格发票,但我所有的尝试都给出了格式错误的表格。然后我想我应该在页面 A 中使用 div 进行重写,并重写弹出打印机页面以反射(reflect)这一点(多个字符串被写入为 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 样式表覆盖了您的更改。可能会在新页面上显式创建表格样式以进行仔细检查。

关于javascript - 无法将格式传递给 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29739098/

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