javascript html jquery - 在页面中打印特定图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11175893/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
html jquery - print specific image in page
提问by AturSams
I have an html page with a link like this:
我有一个带有这样链接的 html 页面:
<a href="javascript:window.print()">Print QR code</a>
When a user clicks it, it does what you think it will.. prints the whole page.. sadly, it does not print the QR code at all. How do I specify what I want to print? Like, lets say I want to print a specific image on the page?
当用户单击它时,它会按照您的想法执行.. 打印整个页面.. 遗憾的是,它根本不打印 QR 码。如何指定要打印的内容?比如,假设我想在页面上打印特定图像?
回答by ricardo_escovar
I know this is an old post, but just wanted to share you this solution that worked very well without using jquery.
我知道这是一篇旧帖子,但只是想与您分享这个在不使用 jquery 的情况下运行良好的解决方案。
http://www.codescratcher.com/javascript/print-image-using-javascript/#comment-762
http://www.codescratcher.com/javascript/print-image-using-javascript/#comment-762
回答by AturSams
I found this plugin that does the trick:
我发现这个插件可以解决这个问题:
http://projects.erikzaadi.com/jQueryPlugins/jQuery.printElement/
http://projects.erikzaadi.com/jQueryPlugins/jQuery.printElement/
$('img#some_id').printElement();