当我使用JavaScript加载脚本时,它返回脚本文件中设置的函数未定义。
这是我在MC.js
内的JavaScript:
window._____$_scriptTag = null;
function setScript(){
var scripts = document.scripts || document.getElementsByTagName("script");
window._____$_scriptTag = scripts[scripts.length - 1];
}
setScript();
MC.install = function(url){
if(typeof url === "string"){
var script = document.createElement("script");
script.src = url;
script.type = "text/javascript";
window._____$_scriptTag.parentNode.insertBefore(script, window._____$_scriptTag);
} else if(typeof url === "object"){
for(i = 0; i < url.length; i++){
var script = document.createElement("script");
script.src = url[i];
script.type = "text/javascript";
window._____$_scriptTag.parentNode.insertBefore(script, window._____$_scriptTag);
}
}
return this;
}
这是我的HTML:
<script src='MoonCheeseJS.js' type='text/javascript'></script>
<span>
<br id='go'>
<a class='my_a'></a>
</span>
<div id='div1' style='height: 250px; width: 100%;'></div>
<script>
MC.install(["qwery.js", "http://cdnjs.cloudflare.com/ajax/libs/qwery/3.4.2/qwery.js", "sizzle.js"]);
Sizzle("head");
</script>
我使用的是Google Chrome 32
Chrome控制台中给出的确切错误:
未捕获的ReferenceError:未定义Sizzle(索引):12