change event not working for a textbox when the value is assigned externally

后端 未结 6 1803
臣服心动
臣服心动 2021-01-22 17:14

I have a textbox and a button. When I click the button, it sets certain value in the textbox. I want to submit the page whenever the value of the textbox is changed.

Ple

6条回答
  •  无人共我
    2021-01-22 17:43

    You need to do this, when you are setting or changing the value of the text input chain it with .change() too:

     $("#click").click(function () {
        $('.set').val('Why am I not getting the alert saying  - Changed! ').change();
      }); //-------------------------------------this one here-------------^^^^^^^^^
    

    So whenever you set the input value this way the change event will be triggered right after click.


    May be this could help

    $("input").on('change keyup', function () {
        alert("Changed!");
    });
    

提交回复
热议问题