我知道這個問題問了很多次,但我試圖找到解決方案,但沒有從可用的SO問題中獲得。「未捕獲的SyntaxError:意外的標識符」
我對Javascript很新鮮。我正嘗試在android中使用cordova創建示例計算應用程序。爲此,我創建了cordova插件。但是我不斷得到兩個問題。
"Uncaught SyntaxError: Unexpected identifier", source: file:///android_asset/www/js/index.js (36)
這裏是index.java代碼和錯誤targetting 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)
這裏是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,
}]
);
}
}
你有一個缺少的逗號。 – SLaks
這是什麼:'console.log(「calculation」);' – Isaac
我補充說,爲了日誌的目的。 –