dagegg2013 2015-08-19 03:23 采纳率: 0%
浏览 4773

使用jquery.qrcode 生成的二维码,使用window.print(); 无法实现打印

使用jquery.qrcode 生成的二维码,使用window.print(); 无法实现打印

代码如下

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>&nbsp;</title>
    <base href="${base}/">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">

    <#include "/include/common.html"/>
    <script type="text/javascript" src="${base}/styles/js/jquery.qrcode.min.js"></script>
    <style type="text/css">
        .barcodeImg{margin:10px 0px}
    </style>

</head>

<body>

<!--startprint-->
<div style="margin:10px">
    <div id="bcTarget" class="barcodeImg"></div>
    <div id="qrcode" class="barcodeImg"></div>
</div>
<!--endprint-->

<input type="button" class="btn" value="打印" onclick="printQrcode();" />
</body>
</html>
<script type="text/javascript">
    $(function(){
        var sc = JSON.stringify(${printSmpleCodeStr});

        $("#bcTarget").empty().barcode(sc, "code128", {barWidth:1.5, barHeight:25,showHRI:true});
        jQuery('#qrcode').qrcode({width: 64,height: 64,text: sc});

//        var bdhtml = window.document.body.innerHTML;
//        var sprnstr = "<!--startprint-->";
//        var eprnstr = "<!--endprint-->";
//        var prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
//        prnhtml = prnhtml.substring(0,prnhtml.indexOf(eprnstr));
//        window.document.body.innerHTML=prnhtml;
//        window.print();
    });

    function printQrcode(){
        var bdhtml = window.document.body.innerHTML;
        var sprnstr = "<!--startprint-->";
        var eprnstr = "<!--endprint-->";
        var prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
        prnhtml = prnhtml.substring(0,prnhtml.indexOf(eprnstr));
        window.document.body.innerHTML=prnhtml;
        window.print();
    }
</script>

界面如下:
图片说明
点击打印按钮:
图片说明

预览时无法显示二维码,无法打印二维码。

  • 写回答

1条回答

  • wjean717 2015-10-09 09:12
    关注

    你现在能打印了吗?我想请教一下,我也是这种方法,想打印,预览能显示二维码,但我想打印在小点的纸张上,请问怎么做?我在打印设置里设置过,但总是打不出来。

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料