打印与页面相同的表
我想要单击图像右侧显示的打印按钮时,打印窗口显示了HTML页面中显示的同一表,现在我从按钮中删除所有类,因此您可以清楚地看到该代码
html表
<div style="text-align: end;margin-bottom: 15px;">
<button onclick="printPageArea('printableArea')" type="button" style="margin-right: 10px;">
<i class="material-icons mdc-button__icon">receipt</i>
</button>
<button type="button" title="Delete">
<i class="material-icons mdc-button__icon">deleteoutline</i>
</button>
</div>
<!-- DataTales Example -->
<div id="printableArea" class="card shadow mb-4">
<table class="table table-striped table-responsive-xxl">
<thead>
<tr class="header">
<th colspan="2"><img src="{% static 'img/logoprint.jpg' %}"></th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>5</td>
</tr>
<tr>
<td>6</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>7</td>
</tr>
</tbody>
</table>
</div>
我的javascript代码
<script>
function printPageArea(areaID){
var printContent = document.getElementById(areaID);
var WinPrint = window.open('', '');
WinPrint.document.write(printContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
}
</script>
我的桌子看起来像
I want when I click on print button shown in right side in image, print window show same table that shown in html page, right now I delete all class from button so you can see that code clearly
html table
<div style="text-align: end;margin-bottom: 15px;">
<button onclick="printPageArea('printableArea')" type="button" style="margin-right: 10px;">
<i class="material-icons mdc-button__icon">receipt</i>
</button>
<button type="button" title="Delete">
<i class="material-icons mdc-button__icon">deleteoutline</i>
</button>
</div>
<!-- DataTales Example -->
<div id="printableArea" class="card shadow mb-4">
<table class="table table-striped table-responsive-xxl">
<thead>
<tr class="header">
<th colspan="2"><img src="{% static 'img/logoprint.jpg' %}"></th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>5</td>
</tr>
<tr>
<td>6</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>7</td>
</tr>
</tbody>
</table>
</div>
my javascript code
<script>
function printPageArea(areaID){
var printContent = document.getElementById(areaID);
var WinPrint = window.open('', '');
WinPrint.document.write(printContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
}
</script>
My table look like this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后,我知道了,只需在您的脚本中添加一些CSS,这将从打印窗口,
脚本函数中更改您的样式。
finally I got it just add some CSS in your script this will change your style from print window,
script function