[jQuery] Document.ready , onload 실행 순서

  • ready() : 사용자가 사이트를 방문할 때 요청한 HTML 문서 객체(document)의 로딩이 끝나면 이벤트를 발생시킨다.
  • load() : 외부에 연동된 (iframe, img, video)의 로딩이 끝나면 이벤트를 발생시킨다.
<!doctype html> 
<html lang="ko"> 
<head> 
<meta charset="UTF-8"> 
<title>HTML5 Document type</title> 
</head>                                                        
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>

    alert('A');

    $(document).ready(function(){
        alert('jquery Ready==');
    });

    $(function(){
        alert('BB');
    });

    window.onload = function(){
        alert('onload');
    };

   alert('c');

</script>


<body> 

<h1>
hello script
</h1>

<form id=reset_test_form>
    메일주소 <input type="text" id ="mail" value="aaaa" /><br>
    전화번호 <input type="text" id="tel"/>
</form>
<input type="button"  id="btn_reset" value="  Reset "></button>

</body> 
</html>

실행을 해보면 A - > C -> onload -> DOM로딩 -> jquery -> BB 순서로 출력이 된다.

즉, $(document).ready 는 태그 등 로딩이 완료되었을 시점에 이벤트를 발생 시킨다.

댓글

Designed by JB FACTORY