//需引入js
<script type="text/javascript" src="jquery-1.9.0.js"></script>
<script type="text/javascript" src="jquery.qrcode.min.js"></script>
<div id="qrcode" style="display:none;"></div>
<a id="download" download="qrcode.jpg" style="display:none;"></a>
.on("click",".span_arcode",function(){//停车场二维码下载
var $self = $(this);
var Id = "";//业务参数
var codeUrl = "http://resource.wlsq.tv/WlsqResourceApi/WxPay/CloudParking/weixin?id="+id;
createQRCode("qrcode",codeUrl,"400","400",codeUrl);
setTimeout(function(){
download();
},1000);
});
//创建二维码
function createQRCode(id,url, width, height, src){
$('#'+id).empty();
$('#'+id).qrcode({
render: 'canvas',
text: url,
width : width, //二维码的宽度
height : height, //二维码的高度
imgWidth : width/4, //图片宽
imgHeight : height/4, //图片高
src: src //图片中央的二维码
});
}
//下载二维码
function download(){
var canvas = $('#qrcode').find("canvas").get(0);
try {//解决IE转base64时缓存不足,canvas转blob下载
var blob = canvas.msToBlob();
navigator.msSaveBlob(blob, 'qrcode.jpg');
} catch (e) {//如果为其他浏览器,使用base64转码下载
var url = canvas.toDataURL('image/jpeg');
$("#download").attr('href', url).get(0).click();
}
return false;
}
生成二维码并下载
最新推荐文章于 2024-04-25 11:38:17 发布