How to get the new value of an HTML input after a keypress has modified it?

后端 未结 6 1769
北恋
北恋 2021-02-05 03:24

I have an HTML input box


I\'ve attached a handler for the \'keyup\' event, but if

6条回答
  •  太阳男子
    2021-02-05 03:48

    To give a modern approach to this question. This works well, including Ctrl+v. GlobalEventHandlers.oninput.

    var onChange = function(evt) {
      console.info(this.value);
      // or
      console.info(evt.target.value);
    };
    var input = document.getElementById('some-id');
    input.addEventListener('input', onChange, false);
    

提交回复
热议问题