An on-click event question in JavaScript.

Asked 2 years ago, Updated 2 years ago, 43 views

Node js Book Example From the following door

Onload becomes an alert window

There's no button event ㅜ It's not even in the log. It doesn't even pop up in the console window.

When clicking a button

Developer Console Window

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

This error occurs.


<!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>

html javascript node.js

2022-09-22 15:37

2 Answers

onClick

https://jsfiddle.net/kuvq32vL/

onclick

https://jsfiddle.net/kuvq32vL/1/

This is the sample code that annotated only sockets in the code you wrote above.

If you look at the link, you can check that it is working normally.

Even if you look at naver_dic.js:1046 among the error messages you added later,

Considering that there is no information related to naver_dic.js in the above code

The reason is expected to be the other parts that are not included in the code you uploaded.


2022-09-22 15:37

Appears to be a case study.

Try modifying to onclick instead of onclick~

Note:
https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onclick


2022-09-22 15:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.