-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
26 lines (22 loc) · 816 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const container = document.querySelector(".container");
const qrInput = document.querySelector(".form input");
const qrImg = document.querySelector(".qr-code img");
const generateBtn = document.querySelector(".form button");
let preValue;
generateBtn.addEventListener("click", () => {
let qrValue = qrInput.value.trim();
if (!qrValue || preValue === qrValue) return;
preValue = qrValue;
generateBtn.innerText = "Generate QR Code...";
qrImg.src = `https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${qrValue}`;
qrImg.addEventListener("load", () => {
container.classList.add("active");
generateBtn.innerText = "Generate QR Code";
});
});
qrInput.addEventListener("keyup", () => {
if (!qrInput.value.trim()) {
container.classList.remove("active");
preValue = "";
}
});