如何在打印前隐藏按钮并在printind过程完成后显示? [英] How can I hide button before printing and show it when printind process has been completed?

查看:76
本文介绍了如何在打印前隐藏按钮并在printind过程完成后显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 id =print_req的打印按钮。我写了一些用于打印页面的Javascript代码,通过单击此按钮触发,我还想在打印前隐藏此按钮,并在整个打印过程后显示它。我的意思是不打印我打印文档中的按钮。这是我的代码:

I have a print button with id="print_req". I wrote some Javascript code for printing a page, which is triggered by clicking on this button, and I also want to hide this button before printing, and show it after whole printing process.i mean not to print button in my printed document. Here is my code:

$(document).ready(function(){
    $("#print_req").click(function(){
        $("#print_req").css("display","none");
        window.print();  
    });

    $("#print_req").css("display","block");
    return false;   
});

这正确地隐藏了该按钮,但是当打印过程完成时,该按钮将不再显示!有什么问题?

This correctly hide that button, but when the printing process get done, the button won't show again! What is the problem?

推荐答案

你错了。您不应该使用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.

这篇关于如何在打印前隐藏按钮并在printind过程完成后显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆