我编写了以下脚本来打印页面。
是否可以在以下标签后不打印 HTML
<font class="productnamecolorSMALL colors_productname"><b>Related Items</b></font>
意思是忽略上面后面的打印
<p>Click the button to print the current page.</p>
<button onclick="myFunction()">Print this page</button>
<script>
function myFunction() {
window.print();
}
</script>
最佳答案
正如 Alexis Wilke 建议的那样,添加一个打印样式表。
此 css 将使用相邻兄弟选择器从打印页面中删除 .productnamecolorSMALL 的第一个相邻兄弟。您可以使用任何您想要标记要删除的内容或在打印时以不同方式显示的内容。因此,只需根据您的需要编辑打印样式表。
html
<link rel="stylesheet" media="print" href="/css/print.css" type="text/css" />
CSS
@media print{
.productnamecolorSMALL+*{
display: none;
}
}
关于jquery - 在某些 HTML 标记后停止打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43103801/