Pure Javascript listen to input value change

后端 未结 6 978
不思量自难忘°
不思量自难忘° 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:54

    Another approach in 2020 could be using document.querySelector():

    const myInput = document.querySelector('input[name="exampleInput"]');
    
    myInput.addEventListener("change", (e) => {
      // here we do something
    });
    

提交回复
热议问题