示例
復制代碼 代碼如下:
<!DOCTYPE HTML>
<HTML>
<HEAD>
<meta charset="utf-8" />
<title>僅img元素創建後卻不添加到文檔中會執行onload事件</title>
</HEAD>
<BODY>
<script>
var img = document.createElement('img');
img.src = "http://www.sinaimg.cn/rny/sinamail57/skins/110318/17/logo.jpg";
img.onload = function(){alert(this.width);};
</script>
</BODY>
</HTML>
iframe,script必須添加到文檔中後才執行回調。