且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

之间的PhoneGap的&QUOT的关系; onBodyLoad()/ onDeviceReady()"功能和jQuery的" $(文件)。就绪()"

更新时间:2023-09-20 23:26:46

$(文件)。就绪总是首先开火,因为它被触发时,所有的DOM元素有加载。图像,JavaScript函数,CSS等可能不被这个时候已经加载。

$(document).ready will always fire first because it is triggered when all the DOM elements have loaded. Images, javascript functions, css, etc. may not have loaded by this time.

所以,PhoneGap的拥有你把的onload 对人体的的onLoad 方法方法,以便它触发时特定部分的DOM已准备就绪。一旦DOM是prepared,您将创建一个事件侦听器,以确保phonegap.js的自身的准备(而不仅仅是应用程序用户界面,例如)。只有phonegap.js加载后,您可以使用它提供。

So PhoneGap has you put the onload method on the body's onLoad method so that it fires when that particular part of the DOM is ready. Once the DOM is prepared, you create an event listener to ensure that phonegap.js itself is ready (and not just the application UI, for example). Only after phonegap.js is loaded can you use the functions that it provides.

所以,是的, $(文件)。就绪将首先开火,但这并不意味着你可以使用phonegap.js(以下简称API调用)。你不能把 $(文件)。就绪的另一个函数内(据我所知),因为它是由DOM加载触发。您的可以的(但不应该)却称,从 $你的 onDeviceReady 函数(文件)。就绪。这样做的问题是,如果该设备实际上不是准备好了,API调用将无法进行。

So yes, $(document).ready will fire first, but that does not mean that you can use phonegap.js (the 'api' calls). You cannot put $(document).ready inside of another function (as far as I know), since it is triggered by the DOM being loaded. You can (but should not) however call your onDeviceReady function from $(document).ready. The problem with this is that if the device is NOT in fact ready, the api calls will not be made.

所以,我会继续用身体的onLoad / onDeviceReady链,他们已成立。让我知道这需要更多的阐述。

So I would continue to use the body onLoad/onDeviceReady chain they have set up. Let me know if this needs more elaboration.