html 局部打印

  • 首先有个调用的方法。printView().
  • function printView() {
        bdhtml = window.document.body.innerHTML;//获取当前页的html代码
        window.document.body.innerHTML = bdhtml;
        sprnstr = "<!--startprint-->";//设置打印开始区域
        eprnstr = "<!--endprint-->";//设置打印结束区域
        prnhtml = bdhtml.substring(bdhtml.indexOf(sprnstr) + 17); //从开始代码向后取html
        prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));//从结束代码向前取html
        window.document.body.innerHTML = "<body>"+prnhtml+"</body>";
        window.print();
        window.document.body.innerHTML = bdhtml;
    }

     

posted @ 2019-10-14 17:08  龙er飞  阅读(594)  评论(0编辑  收藏  举报