JavaScript 打印预览 [英] JavaScript print preview

查看:22
本文介绍了JavaScript 打印预览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何查看从网站生成的发票的打印预览.如果我用脚本打印

How can I see print preview of my invoice generated from website. If I print with the script

<a href="javascript:window.print()">print this page</a>

在打印打印此页"时也打印.我怎样才能隐藏它?

in the print "print this page" also printed. How can I hide it?

推荐答案

解决您问题的以下部分:

Addressing the following part of your question:

在打印"中也打印此页已打印.

in the print "print this page also printed .

我怎样才能隐藏它?

创建一个新的样式表(在本例中,我将其命名为print.css")并将其包含在您的 HTML 中,如下所示:

Create a new stylesheet (in this example, I've named it "print.css") and include it in your HTML as follows:

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

注意 media="print"——这意味着样式表只会在打印页面时使用.

Note the media="print"—this means the stylesheet will only be used when printing the page.

接下来为您的 元素分配一个类,以便我们可以在 CSS 中引用它:

Next assign a class to your <a> element so that we can reference it in CSS:

<a href="javascript:window.print()" class="noPrint">Print this Page</a>

最后,在您的 CSS 文件中,包含以下规则:

Finally, in your CSS file, include the following rule:

.noPrint {
    display: none;
}

现在打印此页面"链接不应出现在页面的打印版本中.

Now the "Print this Page" link shouldn't appear in the printed version of your page.

史蒂夫

这篇关于JavaScript 打印预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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