How do I programmatically trigger an “input” event without jQuery?

前端 未结 4 1575
攒了一身酷
攒了一身酷 2020-11-27 18:33

I installed an event handler on an input using

var element = document.getElementById(\'some-input\');
element.addEventListener(\'input\', functi         


        
4条回答
  •  佛祖请我去吃肉
    2020-11-27 19:31

    This answer is buried in a comment, but is more concise than the most popular answer, so I'm gonna give it a shot as its own answer. Hope it helps.

    element.dispatchEvent(new Event('input', { bubbles: true }));
    

    Or maybe even just...

    element.dispatchEvent(new Event('input'));
    

提交回复
热议问题