【发布时间】:2013-04-10 15:32:17
【问题描述】:
这适用于现代浏览器,但它不能在 IE
下面是 index.html 文件中的代码:
loadJQuery(function () {
alert('hello');
});
然后在另一个文件(通过<script src> 包含)我有:
if (typeof(loadJSInclude) == 'undefined') {
function loadJSInclude(scriptPath, callback)
{
var scriptNode = document.createElement('SCRIPT');
scriptNode.type = 'text/javascript';
scriptNode.src = scriptPath;
var headNode = document.getElementsByTagName('HEAD');
if (headNode[0] != null)
headNode[0].appendChild(scriptNode);
if (callback != null)
{
scriptNode.onreadystagechange = callback;
scriptNode.onload = callback;
}
}
function loadJQuery(task) {
if (typeof(jQuery) == "undefined") {
loadJSInclude('http://code.jquery.com/jquery-latest.min.js', function() {
$(document).ready(task)
});
} else {
$(document).ready(task);
}
}
}
知道为什么这在 IE
【问题讨论】:
-
不要在
if块中使用这种类型的函数声明,使用window.loadJSInclude=function...。 -
怎么样?我真的不明白:(
标签: javascript jquery internet-explorer internet-explorer-8 internet-explorer-9