答案 0 :(得分:0)
<!DOCTYPE html>
<html lang="zh-Hans">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta content="telephone=no" name="format-detection" />
<title>QRcode</title>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery.qrcode.min.js"></script>
</head>
<body>
<div id="qrDiv" style="display: none;"></div>
<div id="imagQrDiv"></div>
<script>
$("#qrDiv").qrcode({
width: 120, //宽度
height: 120, //高度
text: "111" //任意内容
});
</script>
<script>
//从 canvas 提取图片 image
function convertCanvasToImage(canvas) {
//新Image对象,可以理解为DOM
var image = new Image();
// canvas.toDataURL 返回的是一串Base64编码的URL,当然,浏览器自己肯定支持
// 指定格式 PNG
image.src = canvas.toDataURL("image/png");
return image;
}
//获取网页中的canvas对象
var mycanvas1 = document.getElementsByTagName('canvas')[0];
//将转换后的img标签插入到html中
var img = convertCanvasToImage(mycanvas1);
$('#imagQrDiv').append(img); //imagQrDiv表示你要插入的容器id
</script>
</body>
</html>