我知道这个问题很多次,但我试图找到解决方案,但没有得到可用的SO问题.
我是Javascript的新手.我正在尝试使用cordova在android中创建示例计算应用程序.为此,我创建了cordova插件.但我不断得到两个问题.
"Uncaught SyntaxError: Unexpected identifier", source: file:///android_asset/www/js/index.js (36)
这里是index.java代码和错误目标performCalculation()的第一行.
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
document.getElementById("btncalculate").addEventListener("click", performCalculation);
},
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
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);
}
performCalculation: function (){
console.log("in index.html");
var success = function() {
alert("Success");
};
var error = function(message) {
alert("Oopsie! " + message);
};
performAddition(20,10,success,error);
}
};
app.initialize();
这是我得到的第二个例外.
"Uncaught SyntaxError: Unexpected token .", source: file:///android_asset/www/js/calculation.js (3)
这是计算代码.js
var calculationPlugin = {
console.log("calculation");
performAddition: function(first_number, second_number, successCallback, errorCallback) {
console.log("addition");
cordova.exec(
successCallback, // success callback function
errorCallback, // error callback function
'CalculationPlugin', // mapped to our native Java class called "CalculationPlugin"
'addition', // with this action name
[{ // and this array of custom arguments to create our entry
"firstNumber": first_number,
"secondNumber": second_number,
}]
);
}
}
解决方法:
在receiveEvent函数之后,您缺少“,”.
第二个语法错误
计算插件是一个对象,因为你有控制台,抛出错误.从该对象中删除控制台.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。