我正在尝试在HTML中实现打印功能。我知道我可以使用window.print()
打印整个页面,但是如何仅打印特定页面元素?例如特定的<DIV>Some text to print</DIV>
。
最佳答案
您可以使用特定于打印的CSS样式表,并隐藏除您要打印的内容以外的所有内容。<div class="no-print">I won't print</div><div class="something-else">I will!</div>
仅no-print
类将被隐藏,但是带有打印类的所有内容都将显示。
<style type="text/css" media="print">
.no-print { display: none; }
</style>
关于javascript - 如何仅打印选定的HTML元素?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6500962/