Pure Javascript listen to input value change

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

    As a basic example...

    HTML:

    
    

    Script:

    /* event listener */
    document.getElementsByName("Thing")[0].addEventListener('change', doThing);
    
    /* function */
    function doThing(){
       alert('Horray! Someone wrote "' + this.value + '"!');
    }
    

    Here's a fiddle: http://jsfiddle.net/Niffler/514gg4tk/

提交回复
热议问题