Your problem could simply be that you've forgotten the id
attribute within this line of your HTML
<img = 'qrcode' />
Try changing that to this: <img id='qrcode' src=''>
However, if after trying... the problem at hand still persists then I'd recommend you to try the examples below.
Change your HTML
markup to this:
<body>
<img id='qrcode' src=''>
<button id="Btn">Gerar QRcode</button>
<script type="text/javascript" src="script.js"></script>
</body>
Within your javascript
file simply implement this:
document.getElementById("Btn").addEventListener("click", function(){
var x = (Math.random() * 99999999999999999);
document.getElementById('qrcode').src ="https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=" + x;
});
or this version of javascript if you prefer:
document.getElementById("Btn").addEventListener("click", newQR);
function newQR() {
var x = (Math.random() * 99999999999999999);
document.getElementById('qrcode').src ="https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=" + x;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…