Yii - 打印表格内容

时间:2012-07-24 06:11:56

标签: php yii

在我的单页中,我有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>

1 个答案:

答案 0 :(得分:1)

您可以尝试使用jQuery

// U 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();