首先将js文件jquery-barcode-2.0.1.js放到webapp的js文件夹下;
然后在jsp里面引入
<html:uri js="js" path="/js/jquery-barcode-2.0.1.js"></html:uri>
然后就可以使用barcode了:
//需要将条形码放在一个div内所以前面使用div
$('#div_id').empty().barcode("条形码内容", "code128",{//code128为条形码样式
output:'css',
color: '#000000',
barWidth: 2, //单条条码宽度
barHeight: 100, //单体条码高度
addQuietZone: false
});
原文链接:https://blog.csdn.net/weixin_37651459/article/details/79125156
使用:
<style>
.aaa{
margin: 10px 10px 0px 7px;
}
.one{
text-align:center;
/* border-bottom-style:solid;
border-bottom-width:1px; */
}
.two{
height:80px;
/* width:auto; border: 1px solid red;*/
margin-top:15px;
}
.mgl20{
margin-left: 20px;
}
.mgl30{
margin: 0 auto;
}
.three{
height:50px;
/* border:1px solid gray;*/
font-size: 16px;
}
</style>
<div id="printStockTags" style="height:360px;width:240px; padding-top:5px;">
<!-- <img src="in.jpg" style="height:320px;width:210px;" alt=""> -->
<div class="aaa" >
<div id="one" class="one" style="height:40px;text-align: center;">
<span style="font-size:20px;margin-top:10px;display: block;">入库标签</span>
</div>
<div id="two" class="one" style="width:220px; ">
<div id="barcode" class="two"></div>
</div>
<input type="hidden" id="bjid" value="{$bjid}">
<div id="three">
<ul style="list-style:none; margin:0px; padding-top:15px;padding-left:15px; width:auto;height:140px; ">
<li class="three">
产品ID : <span id="proid" cate="1" >{$proid}</span>
</li>
<li class="three">
报价ID : <span id="bj" cate="1" >{$bjid}</span>
</li>
<li class="three">
库 区 : <span>{$area}</span>
</li>
<li class="three">
日 期 : <span><?php echo date('Y-m-d',time()) ?></span>
</li>
</ul>
</div>
</div>
</div>
<script src="/Public/Js/jquery-barcode.js" type="text/javascript"></script>
<script type="text/javascript">
if(true){
$("#barcode").addClass("mgl30");
}else{
$("#barcode").addClass("mgl20");
}
function code128(){
$("#barcode").empty().barcode($('#bjid').val(), "code128",{barWidth:2, barHeight:60,showHRI:true});
}
//页面加载完毕
$(function(){
code128();
});
</script>