Javascript 动态加载.js文件时捕获onload事件?
在IE中动态添加带有JavaScript的脚本标记时,是否捕获了Javascript 动态加载.js文件时捕获onload事件?,javascript,dom,dom-events,onload,Javascript,Dom,Dom Events,Onload,在IE中动态添加带有JavaScript的脚本标记时,是否捕获了onload事件 以下代码适用于FireFox和Chrome,但不适用于IE: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" >
onload
事件
以下代码适用于FireFox和Chrome,但不适用于IE:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
</body>
</html>
<script type="text/javascript" language="javascript">
var elemScript = document.createElement("script");
elemScript.onload = function() {
$("body").html("<div>jQuery Loaded !</div>");
};
elemScript.type = "text/javascript";
elemScript.src = "script/jquery.js";
document.getElementsByTagName("head")[0].appendChild(elemScript);
</script>
var elemScript=document.createElement(“脚本”);
elemScript.onload=函数(){
$(“body”).html(“jQuery-Loaded!”);
};
elemScript.type=“text/javascript”;
elemScript.src=“script/jquery.js”;
document.getElementsByTagName(“head”)[0].appendChild(elemScript);
IE中的脚本标记使用onreadystatechange事件而不是onload: