我正在尝试使用此插件生成qr代码:
我的代码是:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<input id="text" type="text" value="https://hogangnono.com" style="width:80%" /><br />
<div id="qrcode"></div>
<script type="text/javascript" src="javascripts/qrcode.min.js">
var qrcode = new QRCode("qrcode");
</script>
</body>
</html>
但我得到的是一个输入字段,其中包含值,并且不会生成QR码。控制台中没有错误可能是什么问题?
答案 0 :(得分:0)
而不是写
var qrcode = new QRCode("qrcode");
写: -
var qrcode = new QRCode(document.getElementById("qrcode"), "*the name of site*");
QRCode函数的第一个参数是您希望打印QRCode的div。 由于您没有提到打印代码的位置,因此您只能获得输入框。希望这有帮助!
答案 1 :(得分:0)
添加
<script type="text/javascript" src="./javascripts/jquery.min.js"></script>
<script type="text/javascript" src="./javascripts/qrcode.min.js"></script>
到html
答案 2 :(得分:0)
The <script>
element can have a "src" attribute or contents, but not both.
When you wrote
<script type="text/javascript" src="javascripts/qrcode.min.js">
var qrcode = new QRCode("qrcode");
</script>
you were trying to both load the qrcode javascript and specify your own javascript, which is not allowed with the <script>
element.
Instead, load the qrcode javascript (along with the jquery reference as Vinayak mentioned) inside your HTML file's <head>
section:
<script type="text/javascript" src="./javascripts/jquery.min.js"></script>
<script type="text/javascript" src="javascripts/qrcode.min.js"></script>
and then specify your own javascript inside its own script
element below (like you have it, without the "src" tag):
<script>
var qrcode = new QRCode("qrcode");
</script>
That should work for you.