메뉴 건너뛰기

조회 수 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
번호 제목 날짜 조회 수
167 엔터키 / enter key submit form 2018.09.28 1528
166 엔코딩/디코딩 함수 2016.09.21 6033
165 엑셀처럼 td 사이즈 조절하기 2019.01.16 3389
164 에러처리 2019.01.16 1066
163 양력-음력 2015.02.03 7662
162 시간 계산하기 (시/분/초/ 더하기, 빼기) 2021.08.20 1708
161 스타일로 제목 자르기 2016.09.12 5833
160 스마트에디터(SmartEditor)에서 textarea 유효성 체크하기 2018.07.04 3986
159 스마트 에디터 (네이버 에디터) 에디터 내에서 이미지 크기 줄이기.(리사이징) file 2018.07.04 2715
158 셀렉트(select) change 이벤트 (split) 2016.12.23 6009
157 셀렉트(select) change href 이벤트 2016.12.23 5899
156 셀렉트(select) change Ajax 이벤트 2016.12.23 12579
155 선택된 데이터 부모창에 넘기기 (iframe ☞ 부모창) 2015.04.28 6614
154 선택된 select 의 option 값을 다른 select로 넘겨주기 2014.03.01 5668
153 선택(CheckBox) 된 Row 삭제 - 화면에서 추가된 Row 2015.04.28 13538
152 샘플) top left menu 2014.03.01 5513
151 새창을 띠워서 focus주기 2014.03.01 5715
150 새로고침(F5) 금지 2018.03.28 6001
149 비동기 작업의 원리 (JavaScript 엔진, Web API, Task Queue, Event Loop) file 2023.01.20 138
148 브라우저별 이미지 크기 변경 file 2016.11.17 7928
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 13 Next
/ 13

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved