我正在制作一个 phonegap/cordova 项目。正如指南建议的那样,我使用命令行创建了一个框架项目,以创建一个新的 android/phonegap 项目。
在创建的 index.html 文件中有一段代码app.initialize()
,它的代码来自一个名为 index.js 的文件。
我的问题是,我是否必须在我的所有 html 文件中都有这段代码,因为我将使用 jQueryMobile 做前端,我可能需要有几个 html 文件。
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');
},
// 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);
}
};