7
我正在制作phonegap/cordova项目。我使用命令行创建了一个框架项目,如guide建议制作一个新的android/phonegap项目。我是否需要在cordova/phonegap项目中的所有html文件中添加app.initialize()
在创建的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调用新页面(也就是说,只需像打开一个新页面一样打开新的.html),那么请全部调用。 – RaphaelDDL 2013-05-10 17:52:03
读一本书时,它说当检测到一个托管在同一服务器/域上的页面的外部链接时,jQueryMobile将使用Ajax调用该页面。我已经尝试过了,另一个页面工作正常,我只需要确定它是如何工作的。 – 2013-05-11 13:40:09