• 회원가입
  • 로그인
  • 구글아이디로 로그인

[JS-서기] JS 16강 - this객체, 조건분기, 속성설정

1,389  


예제1

 

<script>

function hz(a) { 

     window.alert(a.value);

}

</script>


<input type='button' value='홈짱닷컴 Homzzang.com' name='' class='' onclick='hz(this)'> 


결과 보기 

 

 

 

예제2

 

<script>

function hz(a) { 

     document.getElementById('homzzang').innerHTML = a.value;

}

</script>


<input type='button' value='홈짱닷컴 Homzzang.com' name='' class='' onclick='hz(this)'>


<div id='homzzang'><div>

 

 

결과 보기

 

 

 

예제3

 

<style>

.red {color:red;}

.blue {color:blue;}

</style>


<script>

function chk() { 

     var a = document.getElementById('hz').value;

     if(a == '') {

          document.getElementById('notice').innerHTML= '입력 X';

          document.getElementById('notice').setAttribute('class','red');

     } else {

          document.getElementById('notice').innerHTML= '입력 O';

          document.getElementById('notice').setAttribute('class','blue');

     }

}

</script>


<input type='text' name='hz' value='' placeholder='' id='hz'>

<input type='button' value='확인' name='' class='' onclick='chk()'>

<div id='notice'></div>


 

결과 보기

※ 대소문자 구별 주의


분류 제목
JS-생코 JS 86강 - 상속 (2/3) : 상속의 사용방법
JS-생코 JS 85강 - 상속 (1/3) : 상속이란?
JS-생코 JS 84강 - this (5/5) : apply와 this
JS-생코 JS 83강 - this (4/5) : 객체로서 함수
JS-생코 JS 82강 - this (3/4) : 생성자와 this
JS-생코 JS 81강 - this (2/5) : 메소드와 this
JS-생코 JS 80강 - this (1/5) : 함수와 this
JS-생코 JS 79강 - 전역객체
JS-생코 JS 78강 - 생성자와 new (3/3) : 생성자와 new
JS-생코 JS 77강 - 생성자와 new (2/3) : 객체생성
JS-생코 JS 76강 - 생성자와 new (1/3) : 소개
JS-생코 JS 75강 - 객체지향프로그래밍 (3/3) : 부품화
JS-생코 JS 74강 - 객체지향프로그래밍 (2/3) : 추상화
JS-생코 JS 73강 - 객체지향프로그래밍 (1/3) : 오리엔테이션
JS-생코 JS 72강 - 함수의 호출 (2/2) : apply의 사용
JS-생코 JS 71강 - 함수의 호출 (1/2) : apply 소개
JS-생코 JS 70강 - arguments (2/2) : function length
JS-생코 JS 69강 - arguments (1/2) : arguments란?
JS-생코 JS 68강 - 클로저 (closure) 4/4 : 클로저의 응용
JS-생코 JS 67강 - 클로저 (closure) 3/4 : private variable
23/35
목록
찾아주셔서 감사합니다. Since 2012