html <input type=“text” /> onchange event not working

后端 未结 12 2534
-上瘾入骨i
-上瘾入骨i 2020-11-30 01:13

I am trying to do some experiment. What I want to happen is that everytime the user types in something in the textbox, it will be displayed in a dialog box. I used the

12条回答
  •  日久生厌
    2020-11-30 01:42

    Use .on('input'... to monitor every change to an input (paste, keyup, etc) from jQuery 1.7 and above.

    For static and dynamic inputs:

    $(document).on('input', '.my-class', function(){
        alert('Input changed');
    });
    

    For static inputs only:

    $('.my-class').on('input', function(){
        alert('Input changed');
    });
    

    JSFiddle with static/dynamic example: https://jsfiddle.net/op0zqrgy/7/

提交回复
热议问题