当我的窗口小部件加载以加载依赖项时,我使用以下代码: 我的小部件被加载到其他页面上,因此可以出现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
有什么想法吗?