【发布时间】:2019-01-02 03:31:44
【问题描述】:
当我尝试打印一张小收据时,我遇到了打印问题。所有文件都显示打印。当我点击打印按钮时。打印后,文件打印按钮也打印在页面上。我只需要在页面上打印收据。我使用了 window.print();用于打印。
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class='print' style="border: 1px solid #a1a1a1; width: 300px; background: white; padding: 10px; margin: 0 auto; text-align: center;">
<div class="invoice-title" align="center">
<h1>Pepsi Cola</h1>
</div>
<div class="invoice-title" align="left">
Order # <b> 11111</b>
</div>
<div class="invoice-title" align="right">
Invoice <b>22344</b>
</div>
</br>
</br>
<div>
<div>
<table class="table table-condensed">
<thead>
<tr>
<td class="text-center"><strong>No</strong></td>
<td class="text-center"><strong>Pname</strong></td>
<td class="text-center"><strong>Qty</strong></td>
<td class="text-center"><strong>Price</strong></td>
<td class="text-right"><strong>Total</strong></td>
</tr>
</thead>
<tr>
<td class="text-center">
1
</td >
<td class="text-center">
Cake
</td >
<td class="text-center">
2
</td >
<td class="text-center">120</td>
<td class="text-right">240</td>
</tr>
</table>
</div>
</div>
<div align="right">
Sub Total <b>240</b>
</div>
<div align="right">
Pay <b>220</b>
</div>
<div align="right">
Due <b>20</b>
</div>
<input style="padding:5px;" value="Print Document" type="button" onclick="myFunction()"></input>
</div>
<div>
<div>
</div>
javascript
<script>
function myFunction()
{
window.print();
}
</script>
【问题讨论】:
-
“.我只需要打印收据”..您将页面的哪个部分归类为“收据”?从 HTML 中看不出来。无论如何,您可以使用特定于打印的 CSS(这是使用媒体查询实现的)来隐藏您在打印时不想要的页面位。你可以很容易地用谷歌搜索它。