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

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

    Hopefully this helps someone - I spent 2 hours banging my head against it:

    In IE8 or IE9, if you trigger opening a file input with javascript in any way at all (believe me I've tried them all), it won't let you submit the form using javascript, it will just silently fail.

    Submitting the form via a regular submit button may work but calling form.submit(); will silently fail.

    I had to resort to overlaying my select file button with a transparent file input which works.

提交回复
热议问题