最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - qr code generator in js - Stack Overflow

matteradmin6PV0评论

i am trying to generate qr code using this plugin:

/

my code is:

<!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="" 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>

but all i get is an input field with its value in it and no QR Code is generated. No errors in console either what could be the problem?

i am trying to generate qr code using this plugin:

http://davidshimjs.github.io/qrcodejs/

my code is:

<!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." 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>

but all i get is an input field with its value in it and no QR Code is generated. No errors in console either what could be the problem?

Share Improve this question edited Jun 9, 2018 at 16:17 Vinayak Shrivastava asked May 21, 2018 at 9:00 Vinayak ShrivastavaVinayak Shrivastava 1071 gold badge2 silver badges14 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 1

add

<script type="text/javascript" src="./javascripts/jquery.min.js"></script>
    <script type="text/javascript" src="./javascripts/qrcode.min.js"></script>

to html

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.

Instead of writing

var qrcode = new QRCode("qrcode");

Write :-

var qrcode = new QRCode(document.getElementById("qrcode"), "*the name of site*");

The first parameter of the QRCode function is the div where you want the QRCode to be printed. Since you are not mentioning where to print the code, you are only getting the input box. Hope this helps!

Post a comment

comment list (0)

  1. No comments so far