[英]Print a table from an html page
I have a html page, from which a table needs to be sent to a printer.我有一个 html 页面,需要从中将表格发送到打印机。 I am using window.print right now.. but that prints the whole page... while I need to print just the table.我现在正在使用 window.print .. 但它会打印整页...而我只需要打印表格。 Any ideas?有任何想法吗?
You can use media types print ( here is tips , how print html page using stylesheets).您可以使用媒体类型打印( 这里是提示,如何使用样式表打印 html 页面)。
You can realize that through popup window - in this window show only table and send it to printer.您可以通过弹出窗口 window 实现 - 在此 window 中仅显示表格并将其发送到打印机。
Simple example简单例子
<script>
function printDiv() {
var divToPrint = document.getElementById('areaToPrint');
newWin = window.open("");
newWin.document.write(divToPrint.outerHTML);
newWin.print();
newWin.close();
}
</script>
You can give style display:none
to all unwanted portions of the page.您可以为页面的所有不需要的部分提供样式display:none
。 In that way you can print only table.这样你就可以只打印表格。
for ex:例如:
<style>
@media only print {
footer, header, .sidebar {
display:none;
}
}
</style>
To make it work I need also to put this line between the head section in my document.为了让它工作,我还需要将这一行放在文档的头部部分之间。
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.