본문 바로가기
[LANG]/- JavaScript

[JS]Doit javascript/Jquey 1-1

by Hapco 2022. 6. 3.
728x90
반응형

#객체 ?

-자바스크립트는 객체 기반 프로그래밍 언어

-객체 구성요소 : 속성 , 메소드

객체의 종류

-브라우저객체모델(BOM,Browser Object Model)

-문서객체모델(DOM,document object Model)

내장객체

-문자열(String),Date(날짜),배열(Array),수학(Math)등...

브라우저객체 모델 :

-window,screen,location,history,navigator

window = document , location의 상위객체모델

문서객체모델:

HTML의 문서구조

최상의 객체 <html> 그아래로 <head>와 <body>

단 IE8버전 이하에서는 호환성이 떨어지기 떄문에 사용이 어렵다

내장 객체 생성하기

: 참조변수(인스턴스이름) = new 생성함수();

 <script>
        var tv = new Object();
        tv.color="white";
        tv.price=300000;

        tv.info=function(){
            document.write("tv색상:"+this.color,"<br>");
            document.write("tv가격:"+this.price,"<br>");
        }
       

        var car={
        color:"black",
        price:500000,
        info:function(){
            document.write("car 색상:"+this.color,"<br>");
            document.write("car 가격:"+this.price,"<br>");
        }
        };
        
 
        document.write("<h1>tv 객체 메소드 호출</h1>");
        tv.info();
        document.write("<h1>자동차 객체 메소드 호출</h1>");
        car.info();
    </script>

#날짜객체 생성

참조변수 = new Date(); ex) var t =new Date();

날짜정보를 가져올때(GET)
날짜 정보를 수정할 때(SET)
getFullYear()
연도정보를가져옴
setFullYear()
 
getMonth()
월정보를가져옴(현재월-1)
setMonth()
 
getDate()
일정보를가져옴
setDate
 
getDay()
요일정보를가져옴(일:0~토:6)
setDay
 
getHours()
setHours()
 
getMinutes()
setMinutes()
 
getSeconds()
setSeconds()
 
getMilliseconds()
밀리초(1/1000초)
setMilliseconds()
 
getTime()
1970년1월1일 이후부터 경과된시간을 밀리초로 표현함
setTime()
1970년 1월 1일 이후로부터 경과된 시간을 밀리초로 수정함
toGMTString()
GMT표준 방식으로 문자형데이터로 변환함
toLocaleString()
운영시스템표기방식으로문자형 데이터로 반환

0: 일요일 1: 월요일 2: 화요일 3:수요일 4:목요일 5:금요일 6:토요일

<script>
    var today = new Date();
    var nowMonth = today.getMonth(),
    nowDate =today.getDate(),
    nowDay =today.getDay();

    document.write("<h1>오늘 날짜 정보</h1>");
    document.write("현재 월:"+nowMonth,"<br>");
    document.write("현재 일:"+nowDate,"<br>");
    document.write("현재 요일:"+nowDay,"<br>");

    var worldCup = new Date(2002,04,31);
    var theMonth=worldCup.getMonth(),
    theDate = worldCup.getDate(),
    theDay =worldCup.getDay();
   
    document.write("<h1>월드컵 날짜 정보</h1>");
    document.write("2002 월드컵 월:"+theMonth,"<br>");
    document.write("2002 월드컵  일:"+theDate,"<br>");
    document.write("2002 월드컵  요일:"+theDay,"<br>");


</script>
종류
설명
Math.abs(숫자)
절대값을 반환
Math.Max(숫자)
최대값 반환
Math.min(숫자)
최솟값 반환
Math.pow(숫자,제곱값)
거듭제곱값 반환
Math.random()
0~1 사이의 난수를 반환
Math.round(숫자)
소수점 첫째자리에서 반올림하여 반환
Math.ceil(숫자)
소수점첫쨰자리에서 무조건 올림하여 정수를 반환
Math.floor(숫자)
소수점첫째자리에서 무조건 내림하여 정수를 반환
Math.sqrt(숫자)
숫자의 제곱근 값을 반환
Math.PI
원주율 상수를 반환

'[LANG] > - JavaScript' 카테고리의 다른 글

[JS] javascript 문자열 객체의 메소드  (0) 2022.06.03
[JS]JavaScipt 객체 생성방법  (0) 2022.06.03
[JS]Do_it javascript/query 1회차  (0) 2022.06.03
[JS]Object 객체  (0) 2022.06.03
[JS] 자바스크립트 배열 array  (0) 2022.06.03

댓글