document.onload
이미지 및 기타 외부 콘텐츠를 로드하기 전에 시작됩니다. 문서. 적재 window.onload 전에 이벤트가 발생합니다.
window.onload
이미지, 스크립트, CSS 등이 포함된 전체 페이지가 로드되면 시작됩니다.
예시
다음은 로드를 이해하기 위한 예입니다.
라이브 데모
<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>