我试图在Cordova中点击按钮时显示消息。 我收到了这个错误:
Uncaught TypeError: Cannot read property 'addEventListener' of index.js:6
null
at Object.initialize (index.js:6)
at index.js:39
错误消息指向此行:
btn.addEventListener('click', this.buttonController, false);
我在js文件中有这段代码:
var app = {
initialize: function() {
var btn = document.getElementById("btn1");
btn.addEventListener('click', this.buttonController, false);
},
onDeviceReady: function() {
},
buttonController: function () {
navigator.notification.alert(
'Button Pressed!', // message
alertDismissed, // callback
'Title', // title
'Button Name' // buttonName
);
alert("clicked");
}
};
app.initialize();