메뉴 건너뛰기

조회 수 10885 추천 수 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
번호 제목 날짜 조회 수
27 check_inputbox.js 2014.03.01 5426
26 checkbox 한개 클릭으로 다른모든 checkbox 클릭되게 하기 2014.03.01 5729
25 CheckBox 전체 선택 & 해제 2015.04.28 5607
24 Checkbox : 체크박스 체크여부 확인 file 2015.06.19 19033
23 check box 선택시 색상 변경 file 2014.03.01 6504
22 arguments object 2016.09.21 5670
21 Alert, Confirm을 모달 팝업으로 만들기 file 2021.03.09 3925
20 ajax 사용시 Internal Sever Error 뜨는 경우 2021.03.26 985
19 == / === / != / !== 차이 2018.11.07 1468
18 5초후 자동으로 창닫기 2015.02.03 9062
17 5초 후에 해당페이지로 url 옮기기 2014.02.27 10496
16 3자리마다 콤마찍기 2014.02.27 5774
15 3자리 마다 쉼표만 찍어주는 number_format 함수 2021.03.26 242
14 2단계 트리메뉴 마우스오버(mouseover), 온포커스(onfocus) 구현 2015.04.06 8260
13 (소스)jqury 롤오버 버튼 쉽게 만들기 file 2014.03.01 5803
12 '문자 ↔ 숫자', 타입을 바꿔보자! 2015.02.03 6237
11 '레이블', 반복문을 제어하자! file 2015.02.03 5556
10 'setTimeout', 타이머를 사용하자! file 2015.02.03 7057
9 'setInterval', 타이머를 사용하자! ==setTimeout 2015.02.03 6257
8 'opener', 부모창과 자식창의 텍스트를 교환하자! file 2015.02.03 7336
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 Next
/ 13

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved