如何打印内联CSS样式?
有没有办法打印内联的CSS样式?
我使用此代码来打印部分代码:
w=window.open();
w.document.write($('#printable').html());
w.print();
w.close();
我可以使用外部文件并将其设置为 media=print,但 html 的一部分是由 php 生成的字符,我可以通过为每个可能的结果创建类来实现它,但是那会很痛苦。
有什么想法吗?谢谢。
is there a way to print css styles, that are inline?
I use this code to print part of the code:
w=window.open();
w.document.write($('#printable').html());
w.print();
w.close();
I could use external file and make it media=print, but part of the html are chars, that are generated by php and I could make it by making class for every posible outcome, but that would be pain.
Any ideas? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅演示:http://jsfiddle.net/rathoreahsan/x69UY/
如果您这样做:
Javascript/jQuery 代码:
在这种情况下,当弹出窗口打开并获取
printableDiv
的 HTML 时,打印机的样式将包含在该弹出窗口中,以便打印机将从中读取样式弹出窗口并将以这种方式打印。See the Demo: http://jsfiddle.net/rathoreahsan/x69UY/
What do you think if you do like this:
Javascript/jQuery code:
In this scenario while a popup opens and gets the HTML of
printableDiv
, the styles for printer will be included in that popup so the printer will read styles from popup and will print in that manner.我遇到了同样的问题,因为我使用 instyle 样式动态更改背景颜色,然后颜色不在打印中。
styleSheets[3] 是我的 print.css 文件。
这对我有用:
我将它排除在我用来给某些元素设置背景颜色的 smarty foreach 中。
I had the same problem, because i use instyle style to dynamically change background-color, and then the color was not in the print.
styleSheets[3] is my print.css file.
This worked for me:
I uncluded it in the smarty foreach i use to give some elements a background color.