我看到以下提到stackoverflow的源有关生成QR码,但我做不到: QR code to dataURL
`<div id="img">
<img src="https://example.image.png" />
</div>
<a href="javascript:loadImg();> save </a>
<script>
function loadImg() {
var canvas = $('#img');
console.log(canvas);
var image = canvas.toDataURL("image/png");
}
</script>
当我运行此脚本时,我从chrome开发人员工具收到错误消息,如下所示进行调试:
console.log(); => **init [div#img, context: document, selector: "#img"]**
errorMsg => **ar_direct.do?no=1:19 Uncaught TypeError: canvas[0].toDataURL is not a function
at ch (ar_direct.do?no=1:19)
at <anonymous>:1:1**
因此,我在错误中搜索了“未捕获的TypeError:canvas [0] .toDataURL不是函数”,并检查了画布的控制台日志,如下图所示:
methods and attributes of canvas
但是我找不到canvas的toDataURL()方法。
我如何生成使用canvas.toDataURL()进行成像的QR码?