2009-12-16 100 views
2

在IE中動態添加JavaScript腳本標記時是否捕獲了加載事件?
動態加載.js文件時捕獲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> 

回答