printer

<body>
    <!--startprint-->
    {volist name="data" id="v"}
        <div class="con">
            <div class="zside">
                <img src="img.png" class="bg"/>
                
                <span class="s1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名: <i id="">{$v.cn_name}</i></span>
                <span class="s2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别: <i id="">sex</i></span>
               
            </div>
        </div>
    {/volist}
    <!--endprint-->
    <a href="javascript:printer();" class="btn btn-print">导出PDF</a>
    </body>
    <script src="/__STATIC__/js/jquery.min.js?v=2.1.4"></script>
    <script type="text/javascript">  
    function printer()
    {
        var bdhtml=window.document.body.innerHTML;//获取当前页的html代码   
        var startStr="<!--startprint-->";//设置打印开始区域   
        var endStr="<!--endprint-->";//设置打印结束区域   
        var printHtml=bdhtml.substring(bdhtml.indexOf(startStr)+startStr.length,bdhtml.indexOf(endStr));//从标记里获取需要打印的页面   
        window.document.body.innerHTML=printHtml;//需要打印的页面   
        window.print();   
        window.document.body.innerHTML=bdhtml;//还原界面   
        location.reload();  
    }
</script>

 

posted on 2018-04-24 18:00  _zxd  阅读(214)  评论(0编辑  收藏  举报