jquery:打印出隐藏元素
我正在使用 jQuery Print Element 插件进行打印,但我认为这是一个常见的 css 问题:
如何打印隐藏元素? (将CSS设置为显示:无;)
尝试时,我只得到一张普通的纸。有什么解决办法吗?
谢谢
i'm using the jQuery Print Element plugin for printing but i think it's a general css issue:
how can i print out a hidden element? (with css set to display:none;)
when trying, i'm gettin only a plain sheet. is there any solution?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
正如 DN 建议的那样,使用打印样式表效果会很好。在打印样式表上,将 css 规则设置为
#element {display:block}
。我正在查看 jQuery.printElement 选项,并且有一个选项
overrideElementCSS
。这似乎正是您所需要的。以下是示例代码:将
thisWillBeTheCSSUsedAsWell.css
替换为具有#element {display:block}
规则的打印样式表的路径。As DN suggest, using a print stylesheet will work nicely. On the print stylesheet, set your css rule to
#element {display:block}
.I'm looking at the jQuery.printElement Options, and there is an option
overrideElementCSS
. It seems to be just what you need. Here is the example code:Replace
thisWillBeTheCSSUsedAsWell.css
with the path to your print stylesheet which has the#element {display:block}
rule.您是否包含打印样式表?
Have you included a print stylesheet?
请注意,jQueryUI 使用
!important
意味着您无法使用打印样式表覆盖它,除非您还定义了!important
(而且我认为您还必须链接到您的打印样式表首先在页面标题中,在 jQuery 之前)mind you that jQueryUI uses
!important
means you can't override it with the print stylesheet unless you also define!important
(and I think you also have to link to your print stylesheet first in the page header before the jQuery stuff)看来它只能打印可见元素。就我而言,以下工作有效,
我保留了主要元素(要打印可见且绝对),并在其顶部保留一个元素以将其显示为隐藏。
It seems it could print only visible elements. In my case the following worked
I kept the main element(to be printed visible and absolute), and kept one on top of it to appear it as hidden.
您还可以将元素包装在 div 中,并应用 display: none;对此
You can also wrap your element in a div, and apply display: none; to that