Javascript

자바스크립트 배열 사용하여 css 제어하기

킹king 2018. 4. 24. 16:41
반응형

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        var change = {
            bc : function() {
                document.querySelector("body").style.backgroundColor = "black";
            },
            cd : function() {
                document.querySelector("body").style.color = "white";
            }
        }
 
        function result() {
            change.bc();
            change.cd();
        }
    </script>
 
    <h1>Lorem ipsum dolor sit</h1>
    <button onclick="result()">something_gonna_change</button>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Tempora, voluptas!</p>
 
    <style>
        h1 {
            font-size: 5rem;
        }
        p {
            font-size: 2rem;
            font-weight: 100;
        }
    </style>
</body>
</html>
cs
(누르면 배경색은 검은색이 되고, 글자색은 흰색이 됨)


모든 게시물(특히 과거 게시물)은 잘못된 방법으로 처리한것을 좋다고 써놨을 수 있습니다. 참고만 하시고 틀린게 있다면 댓글 남겨주세요~