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

前端 未结 28 1435
囚心锁ツ
囚心锁ツ 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:06

    You cannot do that in all browsers, supposedly IE does allow it, but Mozilla and Opera do not.

    When you compose a message in GMail, the 'attach files' feature is implemented one way for IE and any browser that supports this, and then implemented another way for Firefox and those browsers that do not.

    I don't know why you cannot do it, but one thing that is a security risk, and which you are not allowed to do in any browser, is programmatically set the file name on the HTML File element.

提交回复
热议问题