반응형
Notice
Recent Posts
Recent Comments
Link
관리 메뉴

bro's coding

window load와 jquery document ready의 차이점 본문

카테고리 없음

window load와 jquery document ready의 차이점

givemebro 2021. 6. 9. 16:50
반응형

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script
	src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<title>Insert title here</title>
</head>
<script type="text/javascript">
	window.onload = function() {
		/*
		window load와 jquery document ready의 차이점
		> window load: img, 동영상과 같은 요소들이 모두 load된 후 호출
		> document ready: DOM이 load되는 시점에 호출
			(이미지나 동영상 같은 자원들이 로드되지 않아도 document 객체가 준비되면 실행)
		jquery document ready가 되는 시점에 익명함수 내에 현 페이질에서 동작될 이벤트에 대한 동작을 바인딩(등록)
		 */

		alert("window onload");
	}
	/*
	jQuery(document).ready(function() {
		alert("jQuery document ready");
		
	})*/
	$(document).ready(function() {
		// 현 페이지에서 이벤트가 발생되면 동작할 행위를 모두 바인딩시킨다

	})
</script>
<body>
	jQuery Basic

	<ul>
		<li><a href="#">test1</a></li>
		<li><a href="#">test2</a></li>
		<li><a href="#">test3</a></li>
	</ul>

</body>
</html>
반응형
Comments