我试图在连接状态发生变化时显示和提醒,但我的代码根本没有效果(下面的提醒没有被执行)。
就这个:
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
document.addEventListener("online", onOnline, false);
document.addEventListener("offline", onOffline, false);
},
// 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);
}
};
function onOffline() {
alert("on");
}
function onOffline() {
alert("off");
}
我的 PhoneGap 版本是 3.3.0-0.18.0。我的目标是 Android,所以我生成了这样的项目:
phonegap create my-app
cd my-app
phonegap run android
我错过了什么?