Pure Javascript listen to input value change

后端 未结 6 991
不思量自难忘°
不思量自难忘° 2020-11-29 23:58

Is there any way I can create a constant function that listens to an input, so when that input value changes, something is triggered immediately?

I am looking for so

6条回答
  •  余生分开走
    2020-11-30 00:58

    Actually, the ticked answer is exactly right, but the answer can be in ES6 shape:

    HTMLInputElementObject.oninput = () => {
      console.log('run'); // Do something
    }
    

    Or can be written like below:

    HTMLInputElementObject.addEventListener('input', (evt) => {
      console.log('run'); // Do something
    });
    

提交回复
热议问题