Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 打印div的内容_Javascript_Jquery_Printing - Fatal编程技术网

Javascript 打印div的内容

Javascript 打印div的内容,javascript,jquery,printing,Javascript,Jquery,Printing,我需要打印div的全部内容。注意div中的滚动条。 但是当我使用Window.print()打印其内容时,它只打印屏幕上可见的部分。我想打印网格中的所有154条记录,但它只打印21条记录 注意:我不想打开新窗口。 编辑: javascript function() { 1. Hide divs that you don't want to print 2. window.print() 3. show the divs you hide in step 1 } 试试这个,但首先要包括这个 或

我需要打印div的全部内容。注意div中的滚动条。 但是当我使用
Window.print()
打印其内容时,它只打印屏幕上可见的部分。我想打印网格中的所有154条记录,但它只打印21条记录

注意:我不想打开新窗口。

编辑:

javascript function()
{
1. Hide divs that you don't want to print
2. window.print()
3. show the divs you hide in step 1
}

试试这个,但首先要包括这个


阅读这篇文章,我认为最好的解决方案是创建一个iframe,将要打印的内容复制到该框架中,然后打印出来。这里有JQuery插件。重复:


另一种可能是使用打印CSS隐藏您不想打印的内容(菜单等),并删除表格上的最小高度,从而删除滚动条。

将样式表与媒体类型的打印一起使用-

link rel="stylesheet" type="text/css" media="print" href="print.css"
并更改DIV样式-

height:auto;
overflow:auto
打印时(使用
window.print()
),DIV将增加高度,并隐藏所有其他DIV。


我在其他插件的基础上编写了上述插件,该插件允许在页面上打印元素(无弹出窗口),并维护页面样式或加载专门用于打印元素的新css样式。

我使用了printThis,它与具有固定高度和滚动条的div非常配合removeInline:true属性打印整个文档,即使在div中只能看到部分文档

function printpage(divId, title) {
                    var divID = "#" + divId;
                    var divTitle = title;
                    $(divID).printThis({
                        debug: false,
                        importCSS: true,
                        importStyle: true,
                        printContainer: true,
                        pageTitle: divTitle,
                        removeInline: true,
                        printDelay: 333,
                        header: null,
                        formValues: true
                    });

                }

对不起,如果你不帮我写一些代码,我就帮不了你。@vaibhav,使用这个jquery插件
http://projects.erikzaadi.com/jQueryPlugins/jQuery.printElement/
您看到了吗:我正在使用的逻辑请参见编辑。printElement()…我需要为此使用一些库吗?
function printpage(divId, title) {
                    var divID = "#" + divId;
                    var divTitle = title;
                    $(divID).printThis({
                        debug: false,
                        importCSS: true,
                        importStyle: true,
                        printContainer: true,
                        pageTitle: divTitle,
                        removeInline: true,
                        printDelay: 333,
                        header: null,
                        formValues: true
                    });

                }