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

//打印页面区域方式一:给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

你可能感兴趣的:(jquery/js 实现 标签 条码 一维码 Web页面 区域打印解决方案 实例)