我正在尝试使用https://github.com/mebjas/html5-qrcode,一旦我扫描任何内容,结果就会被填充到输入字段id "output“中。但是,输出没有在输出id中填充。
var html5QrcodeScanner = new Html5QrcodeScanner(
"qr-reader", { fps: 10, qrbox: 250 });
function onScanSuccess(decodedText, decodedResult) {
// Handle on success condition with the decoded text or result.
console.log(`Scan result: ${decodedText}`, decodedResult);
// ...
//html5QrcodeScanner.clear();
// ^ this will stop the scanner (video feed) and clear the scan area.
}
//Modification Attempt starts here
let QrResult = function(onCloseCallback) {
let scanResultParsed = document.getElementById("output");
}
QrResult.onScanSuccess = function(decodedText) {
this.__onScanSuccess(decodedText);
}
html5QrcodeScanner.render(onScanSuccess);
function onScanSuccess(decodedText, decodedResult) {
console.log(decodedText, decodedResult);
if (html5QrcodeScanner.getState()
!== Html5QrcodeScannerState.NOT_STARTED) {
html5QrcodeScanner.pause(/* shouldPauseVideo= */ true);
}
let scanType = "camera";
if (html5QrcodeScanner.getState()
=== Html5QrcodeScannerState.NOT_STARTED) {
scanType = "file";
}
qrResultHandler.onScanSuccess(decodedText, decodedResult, scanType);
}
html5QrcodeScanner.render(onScanSuccess);
<script src="https://github.com/mebjas/html5-qrcode/releases/download/v2.1.6/html5-qrcode.min.js"></script>
<body>
<div id="qr-reader"></div>
<div id="qr-reader-results">
<input id="output" name="output" type="text" readonly="readonly">
</div>
发布于 2022-02-19 09:48:57
不如像这样
let outputContainer = document.getElementById('output');
var html5QrcodeScanner = new Html5QrcodeScanner(
"qr-reader", { fps: 10, qrbox: 250 });
function onScanSuccess(decodedText, decodedResult) {
// Handle on success condition with the decoded text or result.
console.log(`Scan result: ${decodedText}`, decodedResult);
outputContainer.value = decodedText;
}
html5QrcodeScanner.render(onScanSuccess);
https://stackoverflow.com/questions/70811183
复制相似问题