Phonegap deviceready vs文档准备好了 [英] Phonegap deviceready vs document ready
本文介绍了Phonegap deviceready vs文档准备好了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了phonegap设备就绪事件的问题。我在iOS 6.0下测试。
I am experiencing issues with the phonegap device ready event. I am testing under iOS 6.0.
当设备就绪时,DOM未准备就绪。如果我将事件绑定到 deviceready
事件侦听器中的一些DOM元素,我将不会收到通知,因为这些元素在这个早期不存在。
When device ready is fired, the DOM isn't ready. If I bind events to some DOM Elements in a deviceready
event listener, I will receive no notifications because these elements do not exist at this early time.
那么,什么是最好的做法,等待,直到两个完成加载 - DOM和phonegap?
So what are the best practices for waiting until BOTH have finished loading - DOM and phonegap?
推荐答案
如果您使用的是jquery请尝试此
if your are using jquery try this
$(document).ready(function(){
document.addEventListener("deviceready",onDeviceReady,false);
});
function onDeviceReady(){
//write your function body here
}
如果你使用javascript只尝试这个
if your are using javascript only try this
if(document.readyState === "complete") {
document.addEventListener("deviceready",onDeviceReady,false);
}
function onDeviceReady(){
//write your function body here
}
这篇关于Phonegap deviceready vs文档准备好了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文