Event onChange won't trigger after files are selected from code-generated INPUT element

前端 未结 5 784
执笔经年
执笔经年 2021-01-17 18:00

I\'m playing with JavaScript and wrote simple function that creates INPUT element (type=\"file\") and simulates click.

var createAn         


        
5条回答
  •  囚心锁ツ
    2021-01-17 18:28

    Event listener input.addEventListener ("change" ...

    is not getting registered immediately. It's like wrapping code in setTimeout(fn, 0) which makes it added to the end of the execution queue.

    But input.click(); opens a file selection popup instantly which pauses JavaScript(so the event won't register until the popup is closed). If you wrap input.click in setTimeout(function() { input.click(); }, 0) then it will definitely be executed after the event is registered and this theory may be correct.

    I can't reproduce your problem so this is just pure theory.

提交回复
热议问题