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

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

954  


예제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 46강 - UI,API 그리고 문서 (1/2) : 수업소개
JS-생코 JS 45강 - 모듈 (5/5) : 라이브러리의 사용
JS-생코 JS 44강 - 모듈 (4/5) : 라이브러리란?
JS-생코 JS 43강 - 모듈 (3/5) : Node.js의 모듈화
JS-생코 JS 42강 - 모듈 (2/5) : 모듈화
JS-생코 JS 41강 - 모듈 (1/5) : 모듈이란?
JS-생코 JS 40강 - 객체 (3/3) : 객체지향 프로그래밍
JS-생코 JS 39강 - 객체 (2/3) : 객체와 반복문의 조우
JS-생코 JS 38강 - 객체 (1/3) : 객체의 문법
JS-생코 JS 37강 - 배열 (5/5) : 제거와 정렬
JS-생코 JS 36강 - 배열 (4/5) : 데이터의 추가
JS-생코 JS 35강 - 배열 (3/5) : 배열과 반복문의 조우
JS-생코 JS 34강 - 배열 (2/5) : 배열의 효용
JS-생코 JS 33강 - 배열 (1/5) : 배열의 문법
JS-생코 JS 32강 - 함수 (5/5) : 다양한 정의 방법
JS-생코 JS 31강 - 함수 (4/5) : 출력
JS-생코 JS 30강 - 함수 (3/5) : 입력
JS-생코 JS 29강 - 함수 (2/5) : 함수의 효용
JS-생코 JS 28강 - 함수 (1/5) : 함수란?
JS-생코 JS 27강 - 반복 (6/6) : 반복문의 중첩 (= 이중 반복문) ★★★★★
25/35
목록
찾아주셔서 감사합니다. Since 2012