zoukankan      html  css  js  c++  java
  • javascript区域打印代码

    这段代码是我从Highcharts的代码中改造出来的,非常感谢Highcharts的作者,先链上Highcharts的地址http://www.highcharts.com/,(Highcharts的统计图代码非常棒,功能超强大,大家可以试试)!

    下面附上js区域打印的代码

    /****************************************功能代码******************************/
    (function(){
    window.JPrint = {
        print: function () {
            var doc = document,
            win = window,
            container = doc.getElementById("container"),//这里就是你要打印的区域的id,也可以参数传过来,你们懂的:-)
            origDisplay = [],
            origParent = container.parentNode,
            body = doc.body,
            NONE = 'none',
            childNodes = body.childNodes;
            each = function (arr, fn) {
                var i = 0,
                    len = arr.length;
                for (; i < len; i++) {
                    if (fn.call(arr[i], arr[i], i, arr) === false) {
                        return i;
                    }
                }
            };
            each(childNodes, function (node, i) {
                if (node.nodeType === 1) {
                    origDisplay[i] = node.style.display;
                    node.style.display = NONE;
                }
            });
            body.appendChild(container);
            win.print();
            setTimeout(function () {
                origParent.appendChild(container);
                each(childNodes, function (node, i) {
                    if (node.nodeType === 1) {
                        node.style.display = origDisplay[i];
                    }
                });
            }, 1000);
        }
    };
    }());
    /*******************************下面是用法**********************************/
    JPrint.print();
  • 相关阅读:
    Part 7 Joins in sql server
    Part 9 Union and union all in sql server
    Part 4 using entity framework
    Part 3 ViewData and ViewBag in mvc
    Part 2 How are the URL's mapped to Controller Action Methods?
    Part 1 some difference from asp.net to asp.net mvc4
    Part 18 Indexes in sql server
    c/c++保存日志程序模板
    技术只是工具,你不能用它来代替生活
    网络篇:linux下select、poll、epoll之间的区别总结
  • 原文地址:https://www.cnblogs.com/zhwl/p/4374312.html
Copyright © 2011-2022 走看看