메뉴 건너뛰기

조회 수 10871 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부

페이지 로드후 이벤트 처리하기 1


예제보기)

 

 

  1.  <body>
  2.     <div id="myDiv">
  3.         페이지가 로드되고 난 후 배경색이 Yellow로 변경됩니다.
  4.     </div>
  5.  
  6.     <script type="text/javascript">
  7.         document.getElementById("myDiv").style.backgroundColor='yellow';
  8.     </script>
  9.  
  10.  </body>

 

 

결과보기)

 

 

 

페이지 로드후 이벤트 처리하기 2


예제보기)

 

  1.  <head>
  2.   <title> New Document </title>
  3.     <script type="text/javascript">
  4.     //배경색설정
  5.     //document.getElementById("myDiv").style.backgroundColor = 'yellow';
  6.     //위 문장 오류 발생.. 객체를 만들기전에 참조하려고하기때문에
  7.  
  8.     //페이지 로드시 자바스크립트 실행
  9.     window.onload = pageLoad;
  10.     function pageLoad(){
  11.         document.getElementById("myDiv").style.backgroundColor="green";
  12.         //가장 마지막에 적용된다.
  13.     };
  14.     </script>
  15.  
  16.  </head>
  17.  
  18.  <body>
  19.     <div id="myDiv">
  20.         페이지가 로드되고 난 후 배경색이 Yellow로 변경됩니다.
  21.     </div>
  22.  
  23.     <script type="text/javascript">
  24.         document.getElementById("myDiv").style.backgroundColor='yellow';
  25.     </script>
  26.  
  27.  </body>
  28. </html>
  29.  

 

결과보기)




 

페이지 로드후 이벤트 처리하기 3


예제보기)

 

 

  1. <html>
  2.  <head>
  3.   <title> New Document </title>
  4.     <script type="text/javascript">
  5.     //배경색설정
  6.     //document.getElementById("myDiv").style.backgroundColor = 'yellow';
  7.     //위 문장 오류 발생.. 객체를 만들기전에 참조하려고하기때문에
  8.  
  9.     //페이지 로드시 자바스크립트 실행
  10.     window.onload = pageLoad;
  11.     function pageLoad(){
  12.         changeColor();
  13.         changeSize();
  14.     };
  15.  
  16.     function changeColor(){
  17.         document.getElementById("myDiv").style.backgroundColor="green";
  18.        
  19.     }
  20.     function changeSize(){
  21.         document.getElementById("myDiv").style.height = "100px";
  22.         //사이즈를 변경하려면 대상의 사이즈가 설정되어있어야한다.
  23.     }
  24.     </script>
  25.  
  26.  </head>
  27.  
  28.  <body>
  29.     <div id="myDiv" style = "height:50px;">
  30.         페이지가 로드되고 난 후 배경색이 Yellow로 변경됩니다.
  31.     </div>
  32.  
  33.     <script type="text/javascript">
  34.         document.getElementById("myDiv").style.backgroundColor='yellow';
  35.     </script>
  36.  
  37.  </body>
  38. </html>

 

 

결과보기)

 

 

 

 

 

 

페이지 로드후 이벤트 처리하기 4 : [많이사용하는방법] : 익명함수 : anonymous function 스타일


예제보기)

 

 

 

  1. <html>
  2.  <head>
  3.   <title> window.onload : load 이벤트를 처리하는 onload 이벤트 처리기 </title>
  4.     <script type="text/javascript">
  5.     //배경색설정
  6.     //document.getElementById("myDiv").style.backgroundColor = 'yellow';
  7.     //위 문장 오류 발생.. 객체를 만들기전에 참조하려고하기때문에
  8.  
  9.     //페이지 로드시 자바스크립트 실행
  10.     //함수 지정
  11.     /*
  12.     window.onload = pageLoad;
  13.     function pageLoad(){
  14.         changeColor();
  15.         changeSize();
  16.     };
  17.     */
  18.    
  19.     //[많이사용하는방법] : 익명함수 : anonymous function 스타일
  20.     window.onload = function(){
  21.         changeColor();
  22.         changeSize();
  23.     };
  24.  
  25.  
  26.     function changeColor(){
  27.         document.getElementById("myDiv").style.backgroundColor="green";
  28.        
  29.     }
  30.     function changeSize(){
  31.         document.getElementById("myDiv").style.height = "100px";
  32.         //사이즈를 변경하려면 대상의 사이즈가 설정되어있어야한다.
  33.     }
  34.     </script>
  35.  
  36.  </head>
  37.  
  38.  <body>
  39.     <div id="myDiv" style = "height:50px;">
  40.         페이지가 로드되고 난 후 배경색이 Yellow로 변경됩니다.
  41.     </div>
  42.  
  43.     <script type="text/javascript">
  44.         document.getElementById("myDiv").style.backgroundColor='yellow';
  45.     </script>
  46.  
  47.  </body>
  48. </html>

 

결과보기)





List of Articles
번호 제목 날짜 조회 수
247 유효한 링크인지 확인하는 JAVASCRIPT 2019.01.16 112099
246 [jQuery] 상위부터 차례로 지역 선택하기 2014.03.01 46025
245 Javascript - 이미지 미리보기 회전되어 나옴(EXIF) file 2021.03.09 36361
244 javascript 인쇄 미리보기, 출력, 페이지 설정 등 2014.03.01 32620
243 Checkbox : 체크박스 체크여부 확인 file 2015.06.19 19010
242 날짜 및 시간 입력 구현하기, Bootstrap DateTimePicker file 2017.04.06 16540
241 공백 검사 함수 2015.06.19 14618
240 선택(CheckBox) 된 Row 삭제 - 화면에서 추가된 Row 2015.04.28 13541
239 'focus', 엔터 누르고 이동하자! file 2015.02.03 12857
238 라디오버튼 선택 체크여부 radio checked 2014.03.01 12671
237 셀렉트(select) change Ajax 이벤트 2016.12.23 12586
236 input type file multiple list (파일 업로드 리스트 확인) file 2016.11.17 12437
235 간단한 동적 SELECT 박스 구현하기 2016.10.06 12368
234 GET방식으로 전송시 특수문자함께 전송하는 방법 2016.12.22 12346
233 텍스트박스(input type = "text") 숫자 증가, 감소 시키기 - 쇼핑몰 주문 수량 file 2015.06.19 12288
232 창 크기 최대화 시키기 file 2015.06.19 12228
231 [jQuery] 실시간 검색어 순위 순서대로 보여주기 2014.03.01 12017
230 jquery 메뉴 - 아래로 한번에 전체가 펼처짐 file 2015.04.06 11698
229 'Array', 배열 및 다차원 배열 선언에 대해 알아보자! 2015.02.03 11110
228 랜덤 배너 노출 스크립트 2019.04.29 11051
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 13 Next
/ 13

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved