"JQuery .ready()"의 두 판 사이의 차이

29번째 줄: 29번째 줄:
*예제: http://jmnote.com/jq/ready2.php
*예제: http://jmnote.com/jq/ready2.php


==여러 개 테스트 (비추)==
==여러 개 테스트==
*아래와 같이 여러 개를 써도 정상 작동하지만 굳이 이렇게 할 필요는 없다….
*아래와 같이 여러 개를 써도 정상 작동하지만 굳이 이렇게 할 필요는 없다…. 비추
<source lang='html5'>
<source lang='html5'>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>

2014년 7월 1일 (화) 23:04 판

1 개요

jQuery ready
jQuery onload
  • 자바스크립트의 onload 이벤트를 받는 부분
  • HTML 문서를 모두 로딩하면 실행됨
정확히는 DOM 로딩 완료

2 축약형 ★

html
Copy
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
$(function() {
  alert("로딩 완료");
});
</script>

3 기본형

html
Copy
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
$(document).ready(function() {
  alert("로딩 완료");
});
</script>

4 여러 개 테스트

  • 아래와 같이 여러 개를 써도 정상 작동하지만 굳이 이렇게 할 필요는 없다…. 비추
html
Copy
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
$(document).ready(function() { alert("첫번째 ready"); });
$(document).ready(function() { alert("두번째 ready"); });
$(document).ready(function() { alert("세번째 ready"); });
</script>

5 같이 보기

6 참고 자료