html 使用Bootstrap 3将文件输入转换为形状(http://www.abeautifulsite.net/whipping-file-inputs-into-shape-with-boot

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 使用Bootstrap 3将文件输入转换为形状(http://www.abeautifulsite.net/whipping-file-inputs-into-shape-with-boot相关的知识,希望对你有一定的参考价值。

<span class="btn btn-default btn-file">
  Browse <input type="file">
</span>

<style>
  .btn-file {
    position: relative;
    overflow: hidden;
  }
  .btn-file input[type=file] {
    position: absolute;
    top: 0;
    right: 0;
    min-width: 100%;
    min-height: 100%;
    font-size: 100px;
    text-align: right;
    filter: alpha(opacity=0);
    opacity: 0;
    outline: none;
    background: white;
    cursor: inherit;
    display: block;
  }
</style>

<script>
  $(document).on('change', '.btn-file :file', function() {
    var input = $(this),
        numFiles = input.get(0).files ? input.get(0).files.length : 1,
        label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
    input.trigger('fileselect', [numFiles, label]);
  });
  
  $(document).ready( function() {
      $('.btn-file :file').on('fileselect', function(event, numFiles, label) {
          
          var input = $(this).parents('.input-group').find(':text'),
              log = numFiles > 1 ? numFiles + ' files selected' : label;
          
          if( input.length ) {
              input.val(log);
          } else {
              if( log ) alert(log);
          }
          
      });
  });
  
  $(document).on('change', '.btn-file :file', function() {
    var input = $(this),
        numFiles = input.get(0).files ? input.get(0).files.length : 1,
        label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
    input.trigger('fileselect', [numFiles, label]);
  });
  
  $(document).ready( function() {
      $('.btn-file :file').on('fileselect', function(event, numFiles, label) {
          
          var input = $(this).parents('.input-group').find(':text'),
              log = numFiles > 1 ? numFiles + ' files selected' : label;
          
          if( input.length ) {
              input.val(log);
          } else {
              if( log ) alert(log);
          }
          
      });
  });
</script>

以上是关于html 使用Bootstrap 3将文件输入转换为形状(http://www.abeautifulsite.net/whipping-file-inputs-into-shape-with-boot的主要内容,如果未能解决你的问题,请参考以下文章

Bootstrap 5.x/4.x./3.x的增强HTML 5文件输入,具有文件预览、多选和更多功能。

将 html bootstrap 转换为 react.js jsx 样式后更改 css 样式

详解Bootstrap实现基本布局的方法

html 创建Bootstrap datepicker并使用Moment将时间格式从C#转换为JS可读

CodeIgniter+Bootstrap - 将 HTML 转换为 PDF

使用 Bootstrap 3.1 修复 Firefox 文件输入?