Java script 기본편

김치성·2022년 3월 24일
0

학습내용

1.javascript 변수, 리스트, 조건문
2. 조건문, 버튼을 사용하여 day, night 모드 변경

1. javascript

```
<html>
<body>
    <h1>반복문</h1>
    <script>
        console.log(1);
        for(let i=0; i<2; i=i+1){
            console.log(2);
            console.log(3);
        }
        console.log(4);
    </script>
    <h1>Array + loop</h1>
    <script>
        topics=['html', 'css', 'js', 'python'];
        for(let i=0; i<topics.length; i=i+1){
            
        }
    </script>
</body>

for 문 기본 사용법

2. 조건문, 버튼을 사용하여 day, night 모드 변경

<input type="button" name="button" value="night" onclick="
            if(this.value==='day')
            {
                document.querySelector('body').style.backgroundColor='black';
                document.querySelector('body').style.color='white';
                this.value='night'
            }
            else if(this.value==='night'){
                document.querySelector('body').style.backgroundColor='white';
                document.querySelector('body').style.color='black';
                this.value='day'
            }">
            
            

onclick 부분에 java script를 길게 작성가능하다.
따라서 visualcode에서 onclick의 내용을 작성할때 javascript의 스니펫을 사용할 수 있다.

이때 onclick 내부에서 사용하는 변수로 this를 사용하여 document.queryselector를 사용하여 태그를 선택하듯 자기자신의 태그를 선택할 수 있다.

마무리

오늘은 기존에 얕게 알고 있던 내용들이 많아서 어렵지 않은 수업이였다.

profile
디지털백수

0개의 댓글