글 목록

최신 글과 검색 결과
DEVELOPMENT/Clientside

클라이언트사이드프로그래밍, 11-21 수업 내용

간지뽕빨리턴님

이 글의 목차

    반응형
      클라이언트사이드

    parseInt("60px")

    을 입력하면 숫자만 가져오게 된다.

    그러면 위에 문구에서는 60만 결과값으로 가져오게 된다.

     

    HTML ( 마크업 언어 -> 코딩 한 것을 화면 출력 )

     

    Element.innerHTML

    Element 속성(property) innerHTML

     

    특정 요소 내용 가져와!

    특정 요소 내용 바꿔!

     

    innerHTML = "";

    HTML 요소 접근하여, 해당 텍스트 내용을 바꾸려면 '속성'을 사용해야한다.

     

    document.getElementById를 사용한다.

     

     

     

    [Source Code]


    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
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    <!DOCTYPE html>
    <html lang="ko" dir="ltr">
      <head>
        <meta charset="utf-8">
        <title></title>
     
          <style media="screen">
            div {
              border : 1px solid blue;
              width : 100px;
              height : 100px;
              text-align : center;
              vertical-align : middle;
              line-height : 100px;
              left : 300px;
              top : 300px;
              position : absolute;
            }
            </style>
     
     
          <script type="text/javascript">
            // 박스의 초기 위치
            let divLeft = 0;
            let divTop = 300;
            let handleGo = null;
     
            function moveDiv(left,top) {
              let aDiv = document.querySelector("div");
              aDiv.style.left = left + 'px';
              aDiv.style.top = top + 'px';
              aDiv.innerHTML = `(${left}, ${top})`;
            }
            function directMoveLeft() {
              let aDiv = document.querySelector("div");
              let newLeft = parseInt(aDiv.style.left) - 10;
              aDiv.style.Left = newLeft + 'px';
              let top = parseInt(aDiv.style.top);
              moveDiv(newLeft,top);
            }
     
            function directMoveRight() {
                let aDiv = document.querySelector("div");
                let newLeft = parseInt(aDiv.style.left) + 10;
                aDiv.style.right = newLeft + 'px';
                let top = parseInt(aDiv.style.top);
                moveDiv(newLeft,top);
            }
     
            function goRight() {
              divLeft += 10;
              moveDiv(divLeft, divTop);
            }
            function moveStop() {
              clearInterval(handleGo);
            }
     
            function moveOn() {
              handleGo = setInterval(goRight, 100);
            }
     
            window.onload = function () {
              // 박스 위치를 초기화 한다.
              moveDiv(divLeft, divTop);
              handleGo = setInterval(goRight, 100);
     
              // STOP 버튼의 click 이벤트 핸들러 등록한다.
              document.getElementById("moveStop").addEventListener("click", moveStop);
              document.getElementById("moveOn").addEventListener("click", moveOn);
              document.getElementById("moveRight").addEventListener("click", directMoveRight);
              document.getElementById("moveLeft").addEventListener("click", directMoveLeft);
     
            }
     
          </script>
     
     
      </head>
      <body>
        <h1>Div Moving Control</h1>
        <hr>
        <button type="button" id="moveLeft">Left</button>
        <button type="button" id="moveRight">Right</button>
        <button type="button" id="moveStop">Stop</button>
        <button type="button" id="moveOn">Go</button>
        <hr>
        <div>Javascript</div>
      </body>
     
     
     
     
    </html>
     
     
    <!DOCTYPE html>
    <html lang="ko" dir="ltr">
      <head>
        <meta charset="utf-8">
        <title></title>
        <!---------------------------------------!>
          <style media="screen">
            div {
              border : 1px solid blue;
              width : 100px;
              height : 100px;
              text-align : center;
              vertical-align : middle;
              line-height : 100px;
              left : 300px;
              top : 300px;
              position : absolute;
            }
            </style>
     
        <!---------------------------------------!>
          <script type="text/javascript">
            // 박스의 초기 위치
            let divLeft = 0;
            let divTop = 300;
            let handleGo = null;
     
            function moveDiv(left,top) {
              let aDiv = document.querySelector("div");
              aDiv.style.left = left + 'px';
              aDiv.style.top = top + 'px';
              aDiv.innerHTML = `(${divLeft}, ${divTop})`;
            }
            function goRight() {
              divLeft += 10;
              moveDiv(divLeft, divTop);
            }
            function moveStop() {
              clearInterval(handleGo);
              this.innerHTML= "Go";
              this.onclick = moveOn; // 이벤트 핸들러 변경
            }
     
            function moveOn() {
              handleGo = setInterval(goRight, 100);
              this.innerHTML= "Stop";
              this.onclick = moveStop; // 이벤트 핸들러 변경
     
            }
     
            window.onload = function () {
              // 박스 위치를 초기화 한다.
              moveDiv(divLeft, divTop);
              handleGo = setInterval(goRight, 100);
     
              // STOP 버튼의 click 이벤트 핸들러 등록한다.
              document.getElementById("moveStop").onclick = moveStop;
            }
     
          </script>
        <!---------------------------------------!>
     
      </head>
      <body>
        <h1>Div Moving Control</h1>
        <hr>
        <button type="button" id="moveLeft">Left</button>
        <button type="button" id="moveRight">Right</button>
        <button type="button" id="moveStop">Stop</button>
        <hr>
        <div>Javascript</div>
      </body>
     
     
     
     
    </html>
     
     
     
     
     
     
    // 마지막 예제
     
    <!DOCTYPE html>
    <html lang="ko" dir="ltr">
      <head>
        <meta charset="utf-8">
        <title></title>
      </head>
      <style media="screen">
        table {
          border-collapse: collapse;
        }
        th {
          border: 1px solid gray;
          background-color: #dddddd;
          width : 250px;
        }
      </style>
     
      <script type="text/javascript">
        function gid(id) {
          return document.getElementById(id);
        }
     
        function appendRow(newWord) {
          let mytbody = gid("myTbody");
          // mytbody 객체를 이용하여추가 할 행을 먼저 생성한다.
          let newRow = mytbody.insertRow(mytbody.rows.length)
          // 새로 생성한 행 newRow에 새 칼럼들(cell)을 생성한다. -11월 21일까지 내용
        }
     
        function onKeyDown(){
          if (event.keyCode == 13) {
            if (gid("textinput").value.length > 0){
              gid("codeCheck").innerHTML += gid("textinput").value + ", ";
              gid("textinput").value = ""// input clear
            }
          }
        }
     
        window.onload = function () {
          gid("textinput").addEventListener("keydown", onKeyDown);
        }
     
      </script>
     
      <body>
        <h1>Text & Input & Table Control</h1>
        <hr>
        Input : <input type="text" id="textinput" size=30>
        <br><p id="codeCheck"></p>
     
        <hr>
        <table>
          <thead>
            <th>단어</th>
            <th>단어 문자열 길이</th>
          </thead>
          <tbody id="myTbody">
            </tbody>
        </table>
      </body>
    </html>
     
     
     
    cs