我开始使用 phonegap,我在 phonegap 中学习了很多插件,但是当我想在 phonegap 中使用 QR 扫描仪时,我遇到了困难。有的话给我解决办法
最佳答案
不久前曾在我的 cordova 应用程序中尝试过此 QR 码扫描。希望它能正常工作。代码如下:
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>QR Scanner</title>
</head>
<body>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/app.js"></script>
Click scan button to scan the QR code: <input type="button" value="scan" name = "scan" id="scan"/>
</body>
</html>
app.js
$(document).ready(function() {
document.addEventListener("deviceready", onDeviceReady, false);
});
function onDeviceReady() {
$('#scan').click( function()
{
cordova.plugins.barcodeScanner.scan(
function (result) {
alert("We got a barcode\n" +
"Result: " + result.text + "\n" +
"Format: " + result.format + "\n" +
"Cancelled: " + result.cancelled);
},
function (error) {
alert("Scanning failed: " + error);
});
}
);
}
确保从phonegap-plugin-barcodescanner link添加jquery库js文件和QR码扫描插件试用此示例。
关于javascript - 如何在 Phonegap 中扫描二维码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37983058/