<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="jquery.qrcode.min.js"></script>
<title>生成二维码并可长按保存</title>
</head>
<body>
<div style="display: flex;">
<div id="qrcode"></div>
<div style="display: flex; align-items:center ;">
<text>这是个单纯的二维码在div中</text>
</div>
</div>
<div style="display: flex;">
<div>
<img id="pic" />
</div>
<div style="display: flex; align-items:center ;">
<text>这个是图片二维码,可长按保存</text>
</div>
</div>
</body>
<script>
jQuery('#qrcode').qrcode({
render: "canvas",
width: 100,
height: 100,
text: "https://www.baidu.com"
});
var two = document.getElementsByTagName('canvas')[0];
var test = new Image();
test.src = two.toDataURL("image/png");
document.getElementById('pic').src = test.src;
</script>
</html>
网友评论