Javascript 中的 window.onload 和 document.onload 有什麼區別?
document.onload
它在載入影像和其他外部內容之前啟動。document.onload 事件在 window.onload 之前啟動。
window.onload
它在整個頁面載入完成時啟動,其中包括影像、指令碼、CSS 等等。
示例
下面是一個瞭解 onload 的示例。
<html>
<head>
<title>JavaScript Animation</title>
<script>
<!--
var imgObj = null;
function init() {
imgObj = document.getElementById('myImage');
imgObj.style.position= 'relative';
imgObj.style.left = '0px';
}
function moveRight() {
imgObj.style.left = parseInt(imgObj.style.left) + 10 + 'px';
}
window.onload =init;
//-->
</script>
</head>
<body>
<form>
<img id="myImage" src="/images/html.gif" />
<p>Click button below to move the image to right</p>
<input type="button" value="Click Me" onclick="moveRight();" />
</form>
</body>
</html>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP