0

在我的单页中,我有 2 个表。第一个表是基本信息表。在其他情况下,我将列出要订购的列表。我只想打印第二张桌子。怎么做。

它不是基本打印,使用打印按钮我想单独打印第二个表格的内容。

这是代码,我能够打印第二个表格,但没有应用 css 并且它没有在屏幕上打印。

<script language="javascript">
    function printDiv(divName) {
       var printContents = document.getElementById(divName).innerHTML;
       var originalContents = document.body.innerHTML;

       document.body.innerHTML = printContents;

       window.print();

       document.body.innerHTML = originalContents;
    }
</script> 
<table width="100%" class="ticketpopup"  id='first'>
<tr>
    <td class='label-column' width="100">Address1</td>
    <td class='value-column' width="200" ><?echo $Address1?></td>
    <td class='label-column' width="100">Address2</td>
    <td class='value-column' width="200"><?echo $Address2?></td>
</tr>
<tr>
    <td class='label-column' width="100">Suburb</td>
    <td class='value-column' width="200" ><?echo $Suburb?></td>
    <td class='label-column' width="100">State</td>
    <td class='value-column' width="200"><?echo $State?></td>
</tr>
<tr>
    <td class='label-column' width="100">Postcode</td>
    <td class='value-column' width="200" ><?echo $Postcode?></td>
    <td class='label-column' width="100">Telephone1</td>
    <td class='value-column' width="200"><?echo $Telephone1?></td>
</tr>
<tr>
    <td class='label-column' width="100">FAX    </td>
    <td class='value-column' width="200" ><?echo $FAX?></td>
    <td class='label-column' width="100">ISPCode</td>
    <td class='value-column' width="200"><?echo $ISPCode?></td>
</tr>

<tr>
    <td class='label-column' width="100">Email</td>
    <td class='value-column' width="200" ><?echo $Email?></td>
    <td class='label-column' width="100">PosSoftware</td>
    <td class='value-column' width="200"><?echo $PosSoftware?></td>
</tr>
</table>
<table id="second">
<?  
for ($i=0;$i<10;$i++)
{ 
      print "<tr><td class='label-column' width='100'>Item Name</td>
             <td class='value-column' width='200'><?echo $value[$i];?></td>";
}
?>
</table>

<a href="javascript:void(printDiv('second'));">Print</a>
4

1 回答 1

1

您可以尝试使用 jQuery:

// You can use var w = window.open('blank.html', 'print'); 
var w = window.open('about:blank', 'print'); 
// Copy your second table
$(w.document.body).html('<table>'+$('#second').html()+'</table>');
w.print();
于 2012-07-24T10:21:04.000 回答