我正在制作一个 phonegap/cordova 项目。我使用命令行创建了一个框架项目,作为 guide建议制作一个新的 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);
}
};
最佳答案
由于所有页面都是通过 Ajax 调用调用的,理论上您不需要在所有页面中添加该行。但在某些情况下,您可能想要添加它,例如,如果特定页面可能无法从 ajax 调用中调用,或者用户出于某种奇怪的原因登陆该页面,而不是您的索引页面。
关于javascript - 我是否需要在 cordova/phonegap 项目的所有 html 文件中添加 app.initialize(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16442922/