which event raised when set value of input in javascript

后端 未结 3 2018
隐瞒了意图╮
隐瞒了意图╮ 2021-01-22 01:49

when set value of input in javascript which event raised? i tried these event :(propertychange change keypress paste focus textInput input keyup keydown change) for example:

相关标签:
3条回答
  • 2021-01-22 02:32

    When you set the value programmatically no event will be raised. You can raise it yourself though:

    $('input')[0].value = "sd";
    $('input').first().trigger("change");
    

    Or just using jQuery:

    $('input').first().val("sd").trigger("change");
    
    0 讨论(0)
  • 2021-01-22 02:33

    When a value is changed via a script the change event is not fired, if you want to run a handler then you can trigger the event manually

    $('input').eq(0).val("sd").trigger('change');
    
    0 讨论(0)
  • 2021-01-22 02:47

    You can do something like this. You have to explicitly call change event.

    $('input').val('New Value').change();
    
    0 讨论(0)
提交回复
热议问题