jQuery生成二维码并可在微信中长按保存

直接上代码

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery.qrcode/1.0/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: "http://yangjunwei.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>

参与评论