在我的一页中,我有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>
您可以尝试使用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();