利用npm的某个包和jq生成二维码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div name="controlQrcode"></div>
<script src="./lib/jquery.1.11.1.min.js"></script>
<script type="text/javascript" src="./lib/jquery.qrcode.min.js"></script>
<script language="javascript">
$(function(){
//页面上每一个name='controlQrcode'的div都加上二维码
$("div[name='controlQrcode']").each(function(index,element){
createControlQrcode(element);
})
});
//生成二维码
function createControlQrcode(obj){
var qrcode = $(obj).qrcode({
render: canvas, // 渲染方式有table方式(IE兼容)和canvas方式,默认是canvas
text: '1212',
width: 81,//宽度
height: 81,//高度
colorDark : '#000000',
colorLight : '#ffffff',
correctLevel:3//二维码纠错级别
});
var canvas = $(obj).children("canvas");
//将canvas转换成png图片,才能被打印机识别打印
var img = canvas[0].toDataURL("image/png")
$(obj).html("<img src='" + img + "'>")
}
</script>
</body>
</html>