简体   繁体   English

在Phonegap上使用条形码扫描仪插件在HTML文档上填充字段/标签

[英]Using barcode scanner plugin on Phonegap to populate a field/label on HTML document

hopefully somebody can help me with the following. 希望有人可以在以下方面为我提供帮助。 . . if you look at my below code you can see part of my html submission form, I am using a barcode scanner plugin on phonegap build to try and populate one of the fields. 如果您看下面的代码,您可以看到我的html提交表单的一部分,我在phonegap版本上使用条形码扫描器插件来尝试填充其中一个字段。 The scanner works perfectly but i cannot seem to make it appear in a field similar to my other submission lines... I want it to appear in a field so I can choose to enter serial number manually or use scanner. 扫描仪工作正常,但我似乎无法使其显示在与其他提交行相似的字段中……我希望它显示在一个字段中,因此我可以选择手动输入序列号或使用扫描仪。 . . i also want to pull this data to a database. 我也想将这些数据拉到数据库中。 My Javascript is fine as the scanner does work, just doesnt appear in the way i want it to. 我的Javascript很好,因为扫描仪可以正常工作,只是没有以我想要的方式出现。 Id = "info" gives the result of the scanner. Id =“ info”给出扫描仪的结果。

  <div class="form-group"> <label for="addressline1">Address Line 1:</label> <input type="text" class="form-control" placeholder="Please enter address of installation" required="required" name="addressline1"> </div> <div class="form-group"> <label for="addressline2">Address Line 2:</label> <input type="text" class="form-control" placeholder="Please enter address of installation" name="addressline2"> </div> <div class="form-group"> <label for="addressline3">Address Line 3:</label> <input type="text" class="form-control" placeholder="Please enter address of installation" name="addressline3"> </div> <br> <div class="form-group"> <a href="#" class="btn btn-primary btn-lg btn-block" id="scan">Scan Serial Number</a> </div> <div class="form-group"> <br> <h4><strong>Serial Number:</strong></h4><p id="info" type="number" class="form-control" placeholder="Please use barcode scanner above" required="required" name="info"></p> </div> 

 var app = { initialize: function() { this.bindEvents(); }, bindEvents: function() { document.addEventListener('deviceready', this.onDeviceReady, false); document.getElementById('scan').addEventListener('click', this.scan, false); document.getElementById('encode').addEventListener('click', this.encode, false); }, onDeviceReady: function() { app.receivedEvent('deviceready'); }, receivedEvent: function(id) { var parentElement = document.getElementById(id); var listeningElement = parentElement.querySelector('.listening'); var receivedElement = parentElement.querySelector('.received'); listeningElement.setAttribute('style', 'display:none;'); receivedElement.setAttribute('style', 'display:block;'); console.log('Received Event: ' + id); }, scan: function() { console.log('scanning'); var scanner = cordova.plugins.barcodeScanner; scanner.scan( function (result) { console.log("Scanner result: \\n" + "text: " + result.text + "\\n" + "format: " + result.format + "\\n" + "cancelled: " + result.cancelled + "\\n"); document.getElementById("info").innerHTML = result.text; console.log(result); }, function (error) { console.log("Scanning failed: ", error); } ); }, encode: function() { var scanner = cordova.require("cordova/plugin/BarcodeScanner"); scanner.encode(scanner.Encode.TEXT_TYPE, "http://www.nhl.com", function(success) { alert("encode success: " + success); }, function(fail) { alert("encoding failed: " + fail); } ); } }; 

I figured this out a while ago and forgot to post the answer, it was a very simply fix. 我不久前就发现了这一点,却忘记发布答案,这是一个非常简单的解决方案。 Instead of using use the following . 代替使用以下内容。 . . This allows exactly what I needed. 这正是我所需要的。 Hope this helps somebody else someday. 希望有一天能对别人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM