【发布时间】:2020-12-16 10:20:00
【问题描述】:
我在这里使用二维码扫描仪:https://github.com/mebjas/html5-qrcode
我成功启动了扫描仪,它会返回一个结果。
我想要达到的结果是扫描二维码11次,然后追加到一个列表中。
PS:使用 Framework7 自定义 DOM 调用 $$
我尝试循环它:
$$(document).on('click', '#skvqr', function () {
Html5Qrcode.getCameras().then(devices => {
/**
* devices would be an array of objects of type:
* { id: "id", label: "label" }
*/
if (devices && devices.length) {
var cameraId = devices[1].id;
// .. use this to start scanning.
const html5QrCode = new Html5Qrcode(/* element id */ "reader");
html5QrCode.start(
cameraId,
{
fps: 10, // Optional frame per seconds for qr code scanning
qrbox: 200 // Optional if you want bounded box UI
},
qrCodeMessage => {
// do something when code is read
alert("scan succesful " + qrCodeMessage)
for (i = 11; i >= 1; --i) {
alert("scan succesful " + qrCodeMessage + " Press Ok and Scan " + i + " more times")
$$("#qr-scan-3").append('<input type="text" value=" ' + 'SKV : ' + qrCodeMessage + ' " placeholder="Qr Scan 1">' +
'<span class="input-clear-button"></span>'
);
this.style.display = 'none'
html5QrCode.stop().then(ignore => {
// QR Code scanning is stopped.
}).catch(err => {
// Stop failed, handle it.
});
}
},
errorMessage => {
// parse error, ignore it.
})
.catch(err => {
// Start failed, handle it.
});
}
// ------------------------------------------------------------------------
}).catch(err => {
// handle err
});
});
它会提醒我 11 次警报
("scan succesful " + qrCodeMessage + " Press Ok and Scan " + i + " more times")
它只扫描第一次。
请帮帮我,还在学习 JavaScript
【问题讨论】:
标签: javascript html for-loop html-framework-7