如何在输入文本上显示QRC扫描结果

时间:2018-05-30 06:43:26

标签: javascript html cordova

我正在尝试使用phonegap中的条形码扫描/阅读器。我已经设法读取了二维码,但现在我可以在输入文本上显示结果了。

用于扫描的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正在被正确警告,但是如何在我的输入文本上显示这个问题。

身体内容

    <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结果时,我希望文本输入填充结果。

2 个答案:

答案 0 :(得分:1)

我们可以为文本字段指定一个值,例如$('#qrc').val(qrc); 如果你没有使用jquery,那么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>

答案 1 :(得分:1)

> gfortran -c funkind.f90 
>