如何在输入文本上显示QRC扫描结果 [英] How to show QRC scan results on Input text
问题描述
我正在试用phonegap中的条形码扫描/读取器.我已经设法读取QR码,但是现在我在如何在输入文本上显示结果方面有了很多的想法.
Am trying out barcode scanning/reader in phonegap. I have managed to read the QR codes but now am stack on how I can show results on the input text.
要扫描的Js
<script type="text/javascript">
function scan()
{
cordova.plugins.barcodeScanner.scan(
function (result) {
var qrc = result.text;
alert("We got a barcode\n" +
"Result: " + result.text + "\n" +
"Format: " + result.format + "\n" +
"Cancelled: " + result.cancelled + "\n" +
"QRC: " + qrc);
},
function (error) {
alert("Scanning failed: " + error);
});
}
</script>
已正确警告变量qrc,但麻烦在于如何在我的输入文本中显示该变量.
The variable qrc is being alerted properly, but trouble is on how to show this on my input text.
正文内容
<div data-role="main" class="ui-content">
<a href="" data-role="button" onclick="scan()" >Scan</a>
<form id="Insert" method="POST">
<input type="text" name="qrc" id="qrc" value=""/><br>
<input type="submit" value="Post" id="submit">
</form>
</div>
当QRC扫描结果时,我希望在文本输入中填充结果.
When QRC is scanned results, I want the text input populated with the results.
推荐答案
我们可以为文本字段分配一个值,例如$('#qrc').val(qrc);
如果您不使用jquery,则document.getElementById("qcr").value = qcr;
We can assign a value to text fields, like this $('#qrc').val(qrc);
if you are not using jquery then document.getElementById("qcr").value = qcr;
<script type="text/javascript">
function scan()
{
cordova.plugins.barcodeScanner.scan(
function (result) {
var qrc = result.text;
alert("We got a barcode\n" +
"Result: " + result.text + "\n" +
"Format: " + result.format + "\n" +
"Cancelled: " + result.cancelled + "\n" +
"QRC: " + qrc);
$('#qrc').val(qrc); // Added this line
},
function (error) {
alert("Scanning failed: " + error);
});
}
</script>
这篇关于如何在输入文本上显示QRC扫描结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!