条形码--JsBarcode

 

介绍一下在GitHub生成条形码的js插件→JsBarcode

条码支持的有:

CODE128
  CODE128 (自动模式切换)
  CODE128 A/B/C (强制模式)
EAN
  EAN-13
  EAN-8
  EAN-5
  EAN-2
  UPC (A)
CODE39
ITF-14
MSI
  MSI10
  MSI11
  MSI1010
  MSI1110
Pharmacode
Codabar

 

代码

复制代码
<!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="https://code.jquery.com/jquery-2.1.3.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('Hi!');//or JsBarcode("#svgcode", "Hi!");  

        $("#canvascode").JsBarcode('Hello world!');//or JsBarcode("#canvascode", "Hello world!");  
  
        $("#imgcode").JsBarcode("I'm huangenai!");//or JsBarcode("#imgcode", "I'm huangenai!");  
</script>
</body>
</html>
复制代码

 

 

JsBarcode 我们还可以设置条码的一些属性(可设置属性详细介绍 链接:https://github.com/lindell/JsBarcode/wiki/Options)

复制代码
  <img id="imgcode" />        
  <script>  

JsBarcode("#imgcode", "123", {
  format: "CODE39",//选择要使用的条形码类型
  width:3,//设置条之间的宽度
  height:100,//高度
  displayValue:true,//是否在条形码下方显示文字
  text:"456",//覆盖显示的文本
  fontOptions:"bold italic",//使文字加粗体或变斜体
  font:"fantasy",//设置文本的字体
  textAlign:"left",//设置文本的水平对齐方式
  textPosition:"top",//设置文本的垂直位置
  textMargin:5,//设置条形码和文本之间的间距
  fontSize:15,//设置文本的大小
  background:"#eee",//设置条形码的背景
  lineColor:"#2196f3",//设置条和文本的颜色。
  margin:15//设置条形码周围的空白边距
});
  
  </script>  
复制代码

 

 

GitHub:https://github.com/lindell/JsBarcode

条码生成器:http://lindell.me/JsBarcode/generator/

JsBarcode示例与设置:http://codepen.io/lindell/pen/mPvLXx?editors=1010

简单的JsBarcode演示:http://codepen.io/lindell/pen/eZKBdO?editors=1010

 
分类: JavaScrit
 
好文要顶 关注我 收藏该文  
1
0
 
 
 
« 上一篇:触摸滑动插件 Swiper
» 下一篇:微信JSAPI支付回调
posted @ 2017-01-25 15:39 huangenai 阅读(13662) 评论(4) 编辑 收藏

 

 
#1楼 2017-08-08 16:51 杀头者  
你好,请问能打印出来能扫描么??
#2楼[楼主] 2017-08-08 16:52 huangenai  
@ 杀头者
扫码枪跟手机摄像头都可以扫出来啊
#3楼 2017-08-08 16:52 杀头者  
1
2
3
4
5
6
7
8
9
<img id="orderBarcodeImg"
                 jsbarcode-format="CODE128"
                 jsbarcode-value="BF1_ZX4793981"
                 jsbarcode-width="1"
                 jsbarcode-height="15"
                 jsbarcode-margin="3"
                 jsbarcode-fontSize="10"
                 jsbarcode-textMargin="1"
            />

1
JsBarcode("#orderBarcodeImg").init();

这是我的代码, 期望能收到你回复
#4楼[楼主] 2017-08-08 16:54 huangenai  
@ 杀头者
有什么问题吗?