zoukankan      html  css  js  c++  java
  • jquery 网页局部打印总结

    最近开发过程中遇到了js局部打印的功能,在网上找相关的资料,最终找到了juery.jqprint-0.3.js

    和jquery.PrintArea.js两种。

       最初使用的是jquery.jqprint-0.3.js,是在弹窗的情况下使用,即使出现滚动条也依然能够把所有内容成功打印出来。但是如果在当前页面div中出现滚动条(div内容过多,出现垂直滚动条)的话,则内容打印不全。所以最终选择的的是jquery.PrintArea.js。这是我现在发现的最明显的区别。

      这两个都是打印指定div内的显示内容。

      jquery.PrintArea.js

      代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    <script language="javascript" src="jquery-1.7.1.min.js"></script> 
    <script type="text/javascript" src="jquery.PrintArea.js"></script> 
     
    $(document).ready(function(){ 
        $("#print").click(function(){ 
            $(".my_show").printArea(); 
        }); 
    }); 
     
    <div class="my_show"
    这个是打印时显示的。 
    </div> 
    <div class="my_hidden"
    这个是打印时隐藏的。 
    </div> 
    <input type="button" id="print"/>

    这个插件还提供了一些参数可配置,使用的方法:$(element).printArea(option). 
    这个方法我自己没有用过,大家尝试,有问题的留言哈。 

    参数设置: 
    1.mode:模式,当点击打印按钮时触发模式,默认为iframe,当设置为popup则会新开一个窗口页面打印。 
    2.popTitle:设置新开窗口的标题,默认为空。 
    3.popClose:完成打印后是否关闭窗口,默认为false。

    jquery.jqprint-0.3.js

    代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    <script language="javascript" src="jquery-1.7.1.min.js"></script> 
    <script language="javascript" src="jquery.jqprint.js"></script>
     
    <script type="text/javascript"
        $(document).ready(function() { 
            $("#print").click(function(){ 
                $(".my_show").jqprint(); 
            }) 
        }); 
    </script> 
     
    <div class="my_show"
    这个打印时是显示的 
    </div> 
    <div class="my_hidden"
    这个打印时是隐藏的。 
    </div> 
    <input type="button" id="print"/>

    该插件还提供了一些参数可配置:  
    debug: false,//如果是true则可以显示iframe查看效果(iframe默认高和宽都很小,可以再源码中调大),默认是false 
    importCSS: true, //true表示引进原来的页面的css,默认是true。(如果是true,先会找$(“link[media=print]“),若没有会去找$(“link”)中的css文件) 
    printContainer: true,//表示如果原来选择的对象必须被纳入打印(注意:设置为false可能会打破你的CSS规则)。 
    operaSupport: true//表示如果插件也必须支持歌opera浏览器,在这种情况下,它提供了建立一个临时的打印选项卡。默认是true

  • 相关阅读:
    matplotlib油漆基础
    使用ant编译项目技能
    [Recompose] Refactor React Render Props to Streaming Props with RxJS and Recompose
    [Recompose] Make Reusable React Props Streams with Lenses
    [Recompose] Compose Streams of React Props with Recompose’s compose and RxJS
    [Recompose] Create Stream Behaviors to Push Props in React Components with mapPropsStream
    [Recompose] Stream Props to React Children with RxJS
    [Recompose] Merge RxJS Button Event Streams to Build a React Counter Component
    [Recompose] Handle React Events as Streams with RxJS and Recompose
    [Recompose] Stream a React Component from an Ajax Request with RxJS
  • 原文地址:https://www.cnblogs.com/soundcode/p/7448501.html
Copyright © 2011-2022 走看看