原生js生成二维码
方式一:
document.getElementById('componentQRcode').src = "https://api.qrserver.com/v1/create-qr-code?data=" + ”需要生成的内容“
方式二:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="https://code.jquery.com/jquery-3.0.0.min.js"></script> <script src="./qrcode.js"></script> </head> <body> <input id="text" type="text" value="13020200000000ls" /><br /> <div id="qrcode"></div> </body> <style> #qrcode { width:160px; height:160px; margin-top:15px; } </style> <script> var qrcode = new QRCode("qrcode"); function makeCode () { var elText = document.getElementById("text"); if (!elText.value) { alert("Input a text"); elText.focus(); return; } qrcode.makeCode("13020200000000ls"); } makeCode(); $("#text"). on("blur", function () { makeCode(); }). on("keydown", function (e) { if (e.keyCode == 13) { makeCode(); } }); </script> </html>
qs文件,在网盘