jquery/js 实现 标签 条码 一维码 Web页面 区域打印解决方案 实例

本文介绍了一种通过JavaScript实现的网页局部打印方法,包括两种不同的实现方式:一是通过元素显示状态控制;二是通过HTML片段截取。同时展示了如何在网页中生成并预览条形码图片。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//打印页面区域方式一:给body添加visibility:hidden;隐藏标记,给要打印的部分添加visibility:visible;显示标记 function printTag1(){ $("#entityForm").css("display","none"); $("#tagImgView").css("display","block"); window.print(); $("#entityForm").css("display","block"); }
//区域打印方式二:仅仅打印标签部分 function printTag2() { bdhtml = window.document.body.innerHTML; sprnstr = "<!--startprint-->";//开始标记 eprnstr = "<!--endprint-->";//结束标记 prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17); prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr)); window.document.body.innerHTML = prnhtml; window.print(); }
<form action="" name="entityForm" id="entityForm" target="result" method="post" onsubmit="return checkInfo();"> <input type="hidden" name="id" id="id" value="${tag.id }" /> <table border="0" cellpadding="0" cellspacing="0"> <tr class="main_info"> <td colspan="4"><div id="receipt_title" class="receipt_main_title">一维标签管理</div></td> </tr> <tr class="info"> <!-- <th>标签名称:</th> <td><input type="text" name="name" id="name" class="input_txt" value="${tag.name }" /></td> --> <th>标签编号:</th> <td><input type="text" name="code" id="code" onkeyup="value=value.replace(/[\W]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" class="input_txt" value="${tag.code }" /></td> <td colspan="2"></td> </tr> <tr class="info"> <td colspan="1"></td> <td colspan="2"><a href="javascript:createTag();" id="createTag" class="myBtn"><em>生成标签</em> </a> <a href="javascript:saveTag();" id="saveTag" class="myBtn"><em>保存标签</em> </a></td> <td colspan="1"></td> </tr> <tr class="info"> <td colspan="2">标签预览:</td> <td colspan="2"><a href="javascript:printTag1();" id="printTag" class="myBtn"><em>打印标签</em> </a> </td> </tr> </table> </form> <div id="preview"> <div class="info"> <!--startprint--> <img id="tagImgView" class="PrintOnly" src="${ctx }/tag/barcode?msg=12345678&encode=utf-8&type=code39" /> <!--endprint--> </div> </div>
条码生成采用的开源jar包:barcode4j

转载于:https://www.cnblogs.com/deve/archive/2012/06/18/2569123.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值