zoukankan      html  css  js  c++  java
  • php 实现打印预览的功能

    <inputid="btnPrint" type="button" value="打印"onclick="javascript:window.print();" />
    <inputid="btnPrint" type="button" value="打印预览" onclick=preview(1)/>
    <styletype="text/css" media=print>
    .noprint{display : none}
    </style>
    <pclass="noprint">不须要打印的地方</p>
    <script>
    functionpreview(oper)
    {
    if (oper <10)
    {
    bdhtml=window.document.body.innerHTML;//获取当前页的html代码
    sprnstr="<!–startprint"+oper+"–>";//设置打印開始区域
    eprnstr="<!–endprint"+oper+"–>";//设置打印结束区域
    prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18);//从開始代码向后取html
    prnhtmlprnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//从结束代码向前取html
    window.document.body.innerHTML=prnhtml;
    window.print();
    window.document.body.innerHTML=bdhtml;
    } else {
    window.print();
    }
    }
    </script>
    <p>XXXXX</p>
    <!–startprint1–>要打印的内容<!–endprint1–>
    <inputid="btnPrint" type="button" value="打印"onclick="javascript:window.print();" />
    <inputid="btnPrint" type="button" value="打印预览" onclick=preview(1)/>
    <styletype="text/css" media=print>
    .noprint{display : none}
    </style>
    <pclass="noprint">不须要打印的地方</p>
    <script>
    functionpreview(oper)
    {
    if (oper <10)
    {
    bdhtml=window.document.body.innerHTML;//获取当前页的html代码
    sprnstr="<!–startprint"+oper+"–>";//设置打印開始区域
    eprnstr="<!–endprint"+oper+"–>";//设置打印结束区域
    prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18);//从開始代码向后取html
    prnhtmlprnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//从结束代码向前取html
    window.document.body.innerHTML=prnhtml;
    window.print();
    window.document.body.innerHTML=bdhtml;
    } else {
    window.print();
    }
    }
    </script>
    <p>XXXXX</p>
    <!–startprint1–>要打印的内容<!–endprint1–>
  • 相关阅读:
    超级小白使用pip安装第三方库的正确姿势
    selenium+python自动化测试--解决无法启动IE浏览器及报错问题
    microsoft edge浏览器安装驱动
    超详细MySQL安装及基本使用教程
    Navicat15最新版本破解 亲测可用!!!
    Ubuntu 16.04安装JMeter测试工具
    JMeter_Ubuntu上安装jmeter
    韩国vps推荐-kdatacenter
    全栈之js入门篇
    Web前端之CSS_day5
  • 原文地址:https://www.cnblogs.com/lytwajue/p/6758139.html
Copyright © 2011-2022 走看看