al.qrcode = function(tar,config){ var width = 200; var height = 200; var lvl = 0; var text = ""; if(config){ width = config['width'] || width; height = config['height'] || height; lvl = config['lvl'] || lvl; text = config['text']; } al.load.script('////cdn.anyline.org/plugin/jquery.qrcode.min.js',function(){ tar = $(tar); tar.qrcode({width:width,height:height,correctLevel:lvl,text:text}); function convertCanvasToImage(canvas) { //新Image对象,可以理解为DOM var image = new Image(); // canvas.toDataURL 返回的是一串Base64编码的URL,当然,浏览器自己肯定支持 // 指定格式 PNG image.src = canvas.toDataURL("image/png"); return image; } var alCanvas=document.getElementsByTagName('canvas')[0]; alCanvas.style.display = 'none'//隐藏生成的canvas //将转换后的img标签插入到html中 var img=convertCanvasToImage(alCanvas); tar.append(img);//imagQrDiv表示你要插入的容器id //从 canvas 提取图片 image }); }
al.open({ title:'微信扫描预览', content:'<div style="width:200px;height:200px;" id="qrcode"></div>' }); al.qrcode('#qrcode');