【发布时间】:2015-06-13 03:41:08
【问题描述】:
在这里,我正在尝试使用 IBM Mobilefirst 构建一个混合应用程序,我想在其中使用 Barcode Scanner。为此,我点击了以下链接。
还有,这是我的 index.html:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Barcode</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
<!--
<link rel="shortcut icon" href="images/favicon.png">
<link rel="apple-touch-icon" href="images/apple-touch-icon.png">
-->
<link rel="stylesheet" href="css/main.css">
<script>window.$ = window.jQuery = WLJQ;</script>
<script>
$('#scanButton').bind('click', doScan);
function doScan(){
alert("Hello");
alert(cordova.exec(onScanSuccess, onScanFailure, 'BarcodeScanner', 'scan', []));
}
function onScanSuccess(result) {
alert("We got a barcode\n" +
"Result: " + result.text + "\n" +
"Format: " + result.format + "\n" +
"Cancelled: " + result.cancelled);
}
function onScanFailure(error) {
alert("Scanning failed: " + error);
}
</script>
</head>
<body style="display: none;">
<!--application UI goes here-->
<script src="js/initOptions.js"></script>
<script src="js/main.js"></script>
<script src="js/messages.js"></script>
<h1>Barcode scanner</h1>
<button type="button" id="scanButton" >Scan</button>
</body>
</html>
【问题讨论】:
-
如果您懒得解释这怎么行不通,我们也懒得去尝试猜测问题可能是什么。
-
当我点击扫描按钮时,doScan 函数正在调用,doScan cordova.exex() 内部没有调用,也没有显示任何错误
-
你定义了doScan AFTER你试图做绑定,这意味着doScan还没有被定义,你绑定到一个不存在的函数。如果您甚至完成了基本调试:打开 JS 控制台,您就会看到该错误。它会杀死其余的 JS 代码块
-
之前我尝试过使用 onclick 功能。在这种情况下,它也不起作用