前端使用JsBarcode生成条形码

2020-03-21   阅读:3575   分类:前端    标签: jquery

前端使用JsBarcode生成条形码

:需引入 jsbarcode 插件

JsBarcode安装:

npm install jsbarcode --save
npm install jsbarcode

HTML 生成条形码代码

<!DOCTYPE html>
<html>
 <head> 
  <meta charset="utf-8" /> 
  <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no" /> 
  <title></title> 
  <script type="text/javascript" src="js/jquery.min.js"></script> 
  <script type="text/javascript" src="js/JsBarcode.all.js"></script> 
 </head> 
 <body> 
  <svg id="svgcode"></svg> 
  <!-- or --> 
  <canvas id="canvascode"></canvas> 
  <!-- or --> 
  <img id="imgcode" /> 
  <script>  
        $("#svgcode").JsBarcode('我是条形码');
  </script> 
 </body>
</html>

最终生成的条形码

image.png


OptionDefault valueType
format(选择要使用的条形码类型)"auto" (CODE128)String
width(设置条之间的宽度)2Number
height(高度)100Number
displayValue(是否在条形码下方显示文字)trueBoolean
text (覆盖显示的文本)undefinedString
fontOptions(使文字加粗体或变斜体)""String
font(设置文本的字体)"monospace"String
textAlign(设置文本的水平对齐方式)"center"String
textPosition(设置文本的垂直位置)"bottom"String
textMargin(设置条形码和文本之间的间距)2Number
fontSize(设置文本的大小)20Number
background(设置条形码的背景)"#ffffff"String (CSS color)
lineColor(设置条和文本的颜色)"#000000"String (CSS color)
margin(设置条形码周围的空白边距)10Number
marginTop(设置条形码上方的空白边距)undefinedNumber
marginBottom(设置条形码下方的空白边距)undefinedNumber
marginLeft(设置条形码左边的空白边距undefinedNumber
marginRight(设置条形码右边的空白边距)undefinedNumber
flatfalseBoolean
validfunction(valid){}Funct


【腾讯云】 爆款2核2G3M云服务器首年 61元,2核2G4M云服务器新老同享 99元/年,续费同价

‘简忆博客’微信公众号 扫码关注‘简忆博客’微信公众号,获取最新文章动态
转载:请说明文章出处“来源简忆博客”。http://tpxhm.com/fdetail/294.html

×
觉得文章有用就打赏一下文章作者
微信扫一扫打赏 微信扫一扫打赏
支付宝扫一扫打赏 支付宝扫一扫打赏

文章评论(0)

登录
简忆博客壁纸一
简忆博客壁纸二
简忆博客壁纸三
简忆博客壁纸四
简忆博客壁纸五
简忆博客壁纸六
简忆博客壁纸七
简忆博客壁纸八
头像

简忆博客
勤于学习,乐于分享

置顶推荐

打赏本站

如果你觉得本站很棒,可以通过扫码支付打赏哦!
微信扫码:你说多少就多少~
微信扫码
支付宝扫码:你说多少就多少~
支付宝扫码
×