How to fire JQuery change event when input value changed programmatically?

前端 未结 5 2063
时光说笑
时光说笑 2020-12-10 10:23

I want to fire the JQuery change event when the input text is changed programmatically, for example like this:

5条回答
  •  萌比男神i
    2020-12-10 10:42

    change event only fires when the user types into the input and then loses focus.

    You need to trigger the event manually using change() or trigger('change')

    $("input").change(function() {
      console.log("Input text changed!");
    });
    $("input").val("A").change();
    
    

提交回复
热议问题