jQuery trigger file input

后端 未结 21 1875
梦如初夏
梦如初夏 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:07

    It is too late to answer but I think this minimal setup work best. I am also looking for the same.

      
    Select your new picture

    //css

    .btn-file {
      display: inline-block;
      padding: 8px 12px;
      cursor: pointer;
      background: #89f;
      color: #345;
      position: relative;
      overflow: hidden;
    }
    
    .btn-file input[type=file] {
      position: absolute;
      top: 0;
      right: 0;
      min-width: 100%;
      min-height: 100%;
      filter: alpha(opacity=0);
      opacity: 0;
      cursor: inherit;
      display: block;
    }
    

    jsbin

    bootstrap file input buttons demo

提交回复
热议问题