jQuery trigger file input

后端 未结 21 1882
梦如初夏
梦如初夏 2020-11-22 08:49

Am trying to trigger an upload box (browse button) using jQuery.
The method I have tried now is:

$(\'#fileinput\').trigger(\'click\');   
21条回答
  •  执念已碎
    2020-11-22 09:20

    This is probably the best answer, keeping in mind the cross browser issues.

    CSS:

    #file {
      opacity: 0;
      width: 1px;
      height: 1px;
    }
    

    JS:

    $(".file-upload").on('click',function(){
       $("[name='file']").click();
    });
    

    HTML:

    Upload
    
    

提交回复
热议问题