방통대 컴퓨터과학과 html 웹프로그래밍 정리내용입니다.

1. 객체 : 자바스크립트의 작업의 대상, 실세계 사물을 모델링하기 위해 변수와 함수를 그룹핑한 것

 (속성, 메서드)


 - 객체정의 : 일반 함수와 동일한 형식의 생성자 함수 이용


<!doctype html>

<html lang="en">

 <head>

  <meta charset="UTF-8">

  <meta name="Generator" content="EditPlus®">

  <meta name="Author" content="">

  <meta name="Keywords" content="">

  <meta name="Description" content="">


  <script>

function Student (name, dept, grade) { // 사용자 정의 객체 

this.name = name;

this.dept = dept;

this.grade = grade;

this.print = function () {

document.write(this.name + " " + this.dept + " " + this.grade + "학년<br/>");

}

}


s1 = new Student("개구리", "경영학", 4); 

s2 = new Student("두꺼비", "건축학", 1);

cDate = new Date(); // 내장 객체


document.write(cDate.getMonth()+1 + "월 " + cDate.getDate() + "일 <br/>");


s1.print();

s2.print();

  </script>


  <title>Document</title>

 </head>

 <body>

  

 </body>

</html>

 

- prototype 객체 : 속성 및 메서드의 공유



2. 이벤트 : 어떤 특정한 사건이나 동작(이벤트, 이벤트 핸들러)


<!doctype html>

<html lang="en">

 <head>

  <meta charset="UTF-8">

  <meta name="Generator" content="EditPlus®">

  <meta name="Author" content="">

  <meta name="Keywords" content="">

  <meta name="Description" content="">


  <script>

function changeColor() {

document.body.style.backgroundColor = document.myform.color.value;

}


function rechgColor() {

document.body.style.backgroundColor = "white";

}

  </script>


  <title>Document</title>

 </head>

 <body onLoad="alert('Load 이벤트 발생')">

<form name="myform">

<input type="color" name="color">

<input type="button" value="색상변경" onClick="changeColor()">

<input type="button" value="원래대로" onClick="rechgColor()">

</form>

 </body>

</html>



 - 주요이벤트 : load, unload, focus, blur, change, reset, select

                keydown, keyup, keypress, click, dblclick, mousedown, mouseup, mousemove, mouseover




3. 내장객체

  - String 객체 : 문자의 모양을 지정하거나 문자열을 다루기 위한 객체

    str.split(" ", 2) : 공백을 기준으로 2개로 나눈다.


  - Array 객체 : 배열을 사용하기 위한 객체

    push : 스택에 데이터를 삽입

    concat : 두 개의 배열을 하나의 배열로 만듦

    sort : 배열을 정렬

    pop  : 스택에서 데이터를 삭제

  

  - Date 객체 : 사용자시스템의 날짜와 시간을 관리해주는 객체

    date = new Date();

    date.getFullYear(), date.getMonth()+1, date.getDate(), date.getDay() <- 숫자반환

    date.getHours(), date.getMinutes(), date.getSeconds()


    날짜와 시간의 표시 형식 지정

    now.toGMTString(), now.toLocalString, now.toString


  - Math 객체 : 수학 계산과 관련된 객체

+ Recent posts