且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在打印前隐藏按钮并在printind过程完成后显示?

更新时间:2023-02-11 09:16:07

你错了。您不应该使用JavaScript或使用背景图像来显示和隐藏按钮。您应该使用打印样式表,以便在打印时为页面应用不同的样式。在您的情况下,您可以在此样式表中将显示设置为无[或隐藏的可见性]。

You are going at this wrong. You should not be showing and hiding the button with JavaScript or using a background image to do it. You should be using a print stylesheet that will allow you to apply different styles to the page when it is printed. In your case you would set the display to none [or visibility to hidden] in this stylesheet.

所以你添加一个带有印刷媒体类型的样式表

So you add a stylesheet with the media type for print

<link rel="stylesheet" type="text/css" media="print" href="print.css" />

在print.css中,隐藏按钮

In that print.css, you hide the button

.printButtonClass{ display : none }

presto,当你打印没有JavaScript时按钮隐藏。

And presto, the button hides when you print with no JavaScript.