Yii-打印表格内容


Yii - Printing the table content

在我的单个页面中,我有两个表。第一个表是基本信息表。在其他方面,我会有一个列表的顺序。我只想打印第二张表。如何做到。

这不是基本的打印,有了打印按钮,我想单独打印第二个表格的内容。

这是代码,我可以打印第二个表,但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>

您可以尝试使用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();