0

当我的小部件加载以加载依赖项时,我正在使用以下代码:我的小部件已加载到其他页面上,因此可能会出现 jQuery 冲突,这就是我使用以下方法来避免这种情况的原因。(在除 IE 之外的所有浏览器中都能完美运行)

function ScriptLoadHandler(load) {
    var self = this;
    self.loaded = false;
    self.load = function () {
        if (!self.loaded) {
            load();
            self.loaded = true;
        }
    };
}

function loadScript(scriptURL, afterLoad) {
    var newScript = document.createElement('script');
    newScript.src = scriptURL;
    newScript.type = 'text/javascript';
    document.getElementsByTagName('head')[0].appendChild(newScript);

    if (typeof afterLoad === "function") {
        afterLoad = new ScriptLoadHandler(afterLoad);
        newScript.onreadystatechange = afterLoad.load;
        newScript.onload = afterLoad.load;
    }
}

loadScript('http://code.jquery.com/jquery-1.8.3.js', function () {
    loadScript('http://code.jquery.com/ui/1.9.2/jquery-ui.js', function () {
            // Load all of our $ dependancies before calling noConflict
            js13 = jQuery.noConflict(true);
            main(); // this is the main application function
    });
});

但是在 IE 中我收到以下错误:

SCRIPT5009: 'jQuery' is undefined 
jquery-ui.js, line 6 character 1

SCRIPT5009: 'jQuery' is undefined 
jquery.cookie.js, line 14 character 3

SCRIPT438: Object doesn't support property or method 'cookie' 
widgetTest.js, line 107 character 6

有任何想法吗?

4

1 回答 1

0

请参阅本页底部的代码

于 2013-05-24T21:42:01.610 回答