首页 > 解决方案 > 是否可以使 Window.Print() 方法使用其背景颜色打印突出显示的文本?

问题描述

正如我们可以通过html在以下 w3schools.com链接上复制/粘贴以下内容来验证它突出显示单词highlightedwithyellow background和单词testwith red foreground。但是,如下图所示,当您使用Window.Print()命令打印此 html 页面时,它不会打印 word 的黄色背景highlighted问题:是否有一种解决方法可以使Window.Print()方法也适用于突出显示的文本?

<!DOCTYPE html>
<html>
<body>

<h2>The window.print() Method</h2>

<p>Click the button to print the current page.</p>
<p>This is a <span style='background:yellow;'> highlighted</span> text. And <span style='color:red;'>test</span> for font color.</p>

<button onclick="window.print()">Print this page</button>

</body>
</html>

Print to PDF上述 html 预览的Windows 10 中的快照

在此处输入图像描述

标签: javascripthtmlcss

解决方案


推荐阅读