引入jquery和JsBarcode.all.js(注意:引入JsBarcode.js无效)
github地址:https://github.com/lindell/JsBarcode
代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=0,viewport-fit=cover" />
<title>生成条形码</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="js/JsBarcode.all.js"></script>
</head>
<body>
<script>
window.onload = function bcode(){
var str="",
options = {
format:"CODE128",
displayValue:true,
fontSize:18,
height:100
};
str = ${parameter} ; //parameter是调用功能时带的参数,不带参调用可在初始化时赋值。
JsBarcode("#barcode",str,options); //生成barcode
}
//生成canvascode和imgcode
$("#canvascode").JsBarcode('Hello world!');//or JsBarcode("#canvascode", "Hello world!");
$("#imgcode").JsBarcode("aaa");//or JsBarcode("#imgcode", "aaa");
</script>
<div style="text-align:center" ><img id="barcode" /></div>
</body>
</html>
响应方式:1.window.onload
2.onclick
3.直接响应