jquery - 在某些 HTML 标记后停止打印

标签 jquery css

我编写了以下脚本来打印页面。

是否可以在以下标签后不打印 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/

相关文章:

javascript - 如何在加载缩略图时提供反馈并控制加载顺序

javascript - 如何使用预览从数组 $_FILES 中删除一张图像 - Javascript/PHP

jQuery 对话框 moveToTop 问题

jQuery + Ajax + Haml。 js.erb 文件未触发

jquery - 我更改 css 属性的代码有什么问题?

html - 第一项选择的CSS孙子

jquery - 循环关键帧css3动画8次

javascript - 修改 jQuery getJSON - 添加调用和回调函数

html - Internet Explorer 中的垂直滚动条

javascript - jQuery 自动完成 - 如何为 TextArea 下拉菜单设置 CSS 样式?