In JavaScript can I make a “click” event fire programmatically for a file input element?

前端 未结 28 1405
囚心锁ツ
囚心锁ツ 2020-11-21 06:29

I\'d like to make a click event fire on an tag programmatically.

Just calling click() doesn\'t seem to do anything or at lea

28条回答
  •  误落风尘
    2020-11-21 07:05

    I have been searching for solution to this whole day. And these are the conclusions that I have made:

    1. For the security reasons Opera and Firefox don't allow to trigger file input.
    2. The only convenient alternative is to create a "hidden" file input (using opacity, not "hidden" or "display: none"!) and afterwards create the button "below" it. In this way the button is seen but on user click it actually activates the file input.

    Hope this helps! :)

    
    

提交回复
热议问题