本文介绍了“未捕获的语法错误:意外的标识符";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道这个问题已经问了很多遍了,但是我试图找到解决方案,但是没有从可用的SO问题中得到答案.
I know this question asked many times but I tried to find solution but didn't get from available SO questions.
我是Java语言方面的新手.我正在尝试使用cordova在android中创建示例计算应用程序.为此,我创建了cordova插件.但是我不断遇到两个问题.
I am very newbie on Javascript. I am trying to create sample calculation application in android using cordova. For that, I created cordova plugin. But I am getting two issues continuously.
"Uncaught SyntaxError: Unexpected identifier", source: file:///android_asset/www/js/index.js (36)
这是index.java代码和错误定位performCalculation()的第一行.
here is index.java code and error targetting performCalculation() first line.
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();
这是我得到的第二个例外.
Here is my second exception which I am getting.
"Uncaught SyntaxError: Unexpected token .", source: file:///android_asset/www/js/calculation.js (3)
这是Calculation.js的代码
and Here is code of calculation.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,
}]
);
}
}
推荐答案
第一个语法错误
第二种语法错误
这篇关于“未捕获的语法错误:意外的标识符";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!