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

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

    If you want the click method to work on Chrome, Firefox, etc, apply the following style to your input file. It will be perfectly hidden, it's like you do a display: none;

    #fileInput {
        visibility: hidden;
        position: absolute;
        top: 0;
        left: -5000px;
    }
    

    It's that simple, I tested it works!

提交回复
热议问题