자바스크립트의 온클릭 이벤트 질문입니다.

조회수 8475회

노드 js 책 예제 중 아래와같은 문에서

onload는 alert창이 되는데

버튼 이벤트가 들어가지 않네요 ㅜ 로그에도 없고요. 콘솔창에도 안뜨고요..

버튼을 클릭할때

개발자 콘솔창에

Uncaught TypeError: Cannot read property 'length' of undefined naver_dic.js:1046

이런 오류가 발생합니다.


<!DOCTYPE html>
<html>
<head>
  <title></title>
  <script src="/socket.io/socket.io.js"></script>
  <script>
    window.onload = function(){
      alert("onload");
      var socket = io.connect();

      socket.on('smart',function(data){
        alert(data);
      });

      document.getElementById('button').onClick = function(){
         alert('button click');
      };

    };

  </script>
</head>
  <body>
      <input type="text" id="text"  />
      <input type="button" id="button" name="button" value="echo" />
  </body>
</html>

2 답변

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)