【发布时间】:2013-05-02 19:35:10
【问题描述】:
我正在制作一个 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 调用新页面(也就是说,只需像打开新页面一样打开新的 .html),那么是的,全部调用。
-
读一本书,它说当检测到一个页面的外部链接时,托管在同一服务器/域上,jQueryMobile 将使用 Ajax 调用该页面。我已经尝试过了,其他页面运行顺利,我只需要确定它是否应该这样工作。
标签: javascript android html cordova jquery-mobile