gpt4 book ai didi

javascript - jQuery 的 .getScript()... 我做错了什么?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:46:48 26 4
gpt4 key购买 nike

我正在使用 Phonegap 编写 iPhone 应用程序。我有本地 .html.js 文件。以下是我的 index.html 文件:

function onBodyLoad() {
document.addEventListener("deviceready", deviceReady, false);
}

function deviceReady() {
$.getScript("js/order.js");
}

我研究了又研究,但就是想不通为什么 $.getScript 方法没有调用我的“order.js”文件。有任何想法吗?或者有没有其他方法可以在我的 index.html 的 deviceReady 函数中调用这个 .js 文件?

最佳答案

对我来说,以下解决方案非常有效。

  1. 添加使用 ajax 并缓存加载脚本的自定义 jQuery 函数:

    function init()
    {
    // Create a custom cached script importer based on ajax
    jQuery.cachedScript = function(url, options)
    {
    // Allow custom options, but dataType, cache and url are always predefined
    options = $.extend(options || {},
    {
    dataType: "script",
    cache: true,
    url: url
    });
    return jQuery.ajax(options);
    };

    importScripts();
    }
  2. 导入脚本并可选择处理donefail:

    function importScripts()
    {
    $.cachedScript("js/events.js")
    // Wait for the script to be loaded, before adding the listener
    .done(function()
    {
    document.addEventListener("deviceready", onDeviceReady, false);
    });
    $.cachedScript("js/navigation.js");
    $.cachedScript("js/mark.js");
    }

就是这样:)可以找到更多信息 here .

关于javascript - jQuery 的 .getScript()... 我做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8844022/

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