使用 jquery printElement 打印所有 div 内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4932451/
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
Print all div content with jquery printElement
提问by szaman
I am trying to print my div content using printElementplugin. The div has a lot of text with in so there is a scrollbar. The problem is that plugin prints only the part of text which is actually on the screen. How can I print all of the text?
我正在尝试使用printElement插件打印我的 div 内容。div 中有很多文本,因此有一个滚动条。问题是插件只打印实际在屏幕上的文本部分。如何打印所有文本?
EDIT:
编辑:
I need a solution which will print this div with styles which are in external css.
我需要一个解决方案,它将使用外部 css 中的样式打印此 div。
采纳答案by benhowdle89
回答by Jason
https://github.com/jasonday/printThis
https://github.com/jasonday/printThis
Configurable with additional css files, and other options.
可配置其他 css 文件和其他选项。
回答by user357086
<div class="printclass">Print</div>
<div id="mydivid">
Your content goes here
</div>
</div>
<script type="text/javascript">
$(function(){
$( ".printclass" )
.attr( "href", "javascript:void(0)")
.click(function(){
// Print the DIV.
$( "#mydivid" ).print();
// Cancel click event.
return( false );
});
});
</script>