gpt4 book ai didi

javascript - 使用 jQuery Mobile 和 $(document).ready 与 PhoneGap Build 和 document.addEventListener ("deviceready")

转载 作者:行者123 更新时间:2023-11-30 12:34:11 24 4
gpt4 key购买 nike

我已经完成了与此相关的两个问题的解决方案 - JQuery document.ready vs Phonegap devicereadyCorrect way of using JQuery-Mobile/Phonegap together?我仍然离解决方案还很远。

我们的问题是 PhoneGap Build 插件。我们正在使用 Device 插件将特定的 UI 组件位置和大小定位到 iPhone 4 和 5。为此,我们需要调用事件监听器,使用 Device 插件获取设备型号,设置变量 (iOSversion = true)然后在构建 UI 时使用该变量。

我们无法让它工作。

我们正在使用 jQuery Mobile,所以一切都在一个

 $(document).ready(function(

这有

document.addEventListener("deviceready", false); 

在其中,以及我们其余的脚本和 UI 初始化脚本。 jQM 是模板,但我们正在构建基于 JSON 数据的内容和 UI 组件。到目前为止,一切都很好。

问题是 UI 初始化脚本似乎在事件监听器完成它所做的任何事情之前就开始了,因此 iOS 版本在 UI 脚本运行时永远不会为真。

是的,我们可以在 onDeviceReady 中调用它:

 document.addEventListener("deviceready", onDeviceReady, false);

但是我们无法在浏览器中进行测试。

我确信我缺少一些简单的解决方案,但我们已经研究了一天,这是最后的障碍,让每个人都非常沮丧。

最佳答案

我得到了答案。

window.cordova 在 Phonegap Build 中公开。所以我检查它是否存在,在 jQuery $(document).ready 中是这样的:

if ( !!window.cordova ) {
// phonegap script has loaded so have our
// initializeApplication called when the device is ready
document.addEventListener("deviceready",
initializeApplication, false);
}
else {
// running in browser without phonegap so
// manually call initializeApplication
initializeApplication();
}
function initializeApplication() {
// do everything here to initialize the
// application and its UI
}

关于javascript - 使用 jQuery Mobile 和 $(document).ready 与 PhoneGap Build 和 document.addEventListener ("deviceready"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26640727/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com