zoukankan      html  css  js  c++  java
  • JavaScript页面中的打印功能

    <script type="text/javascript">

     function preview(oper) {
                if (oper < 10) {
                    bdhtml = window.document.body.innerHTML; //获取当前页的html代码
                    sprnstr = "<!--startprint" + oper + "-->"//设置打印开始区域
                    eprnstr = "<!--endprint" + oper + "-->"//设置打印结束区域
                    prnhtml = bdhtml.substring(bdhtml.indexOf(sprnstr) + 18); //从开始代码向后取html
                    prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr)); //从结束代码向前取html
                    window.document.body.innerHTML = prnhtml;
                    window.print();
                    window.document.body.innerHTML = bdhtml;
                } else {
                    window.print();
                }
            }
        </script>
     <!--startprint1-->
     <table width="100%" border="0" cellspacing="2" cellpadding="2">

    <tr>
    <td>2</td>
    <td>3</td>
    <td>4</td>
    <td>5</td>
    </tr>
    <tr>
    <td>2</td>
    <td>3</td>
    <td>4</td>
    <td>5</td>
    </tr>
    <tr>
    <td>2</td>
    <td>3</td>
    <td>4</td>
    <td>5</td>
    </tr>
    </table>

     <!--endprint1-->
     <input class="button" id="Button1" onmouseover="this.className='buttonover'" onmouseout="this.className='button'" type="button" value="打 印" onclick="preview(1)" />

  • 相关阅读:
    葵花宝典,参考学习网站收藏
    安卓工具
    马帮
    C89:vs输出调试信息
    OSG:中级篇 拖拽器类
    OSG:幼儿园篇 第六章 碰撞检测类
    OSG:幼儿园篇 第三章 节点坐标变换类
    OSG:幼儿园篇 第五章 界面交互类
    C++11:智能指针
    OSG:幼儿园篇 第四章 节点回调类
  • 原文地址:https://www.cnblogs.com/jameslif/p/2584310.html
Copyright © 2011-2022 走看看