jQuery:get file MIME

MIME.png
<!DOCTYPE html>
<html>
<head>
  <title>MEME Fetcher</title>
  <script type="text/javascript" src="file:///D:/PHPStormProjects/TechSupp/public/assets/js/jquery.min.js"></script>
  <style type="text/css">
    .mime-item{
      border-bottom: 1px solid #efefef;
      padding: 4px;
      display: flex;
      font-size: .8rem;
    }
    .mime-item span:first-child{
      flex:1;
    }
    .mime-item span:last-child{
      flex:4;
    }
    .wrapper{
      width: 850px;
      margin: 0 auto;
      border: 0, 1px solid #dedede;
      padding-top: 2rem;
    }
    #file-mask{
      width: 80%;
      display: block;
      border: 1px solid #dedede;
      border-radius: 4px;
      background-color: #efefef;
      font-size: .8rem;
      padding:3px 0;
      text-indent: 1rem;
    }
    .sr-only{
      display: none !important;
      transition: 500ms all ease-in;
    }
    #mime-list{
      display: block;
      margin-top: 2rem;
      width: 80%;
      min-height: 120px;
      height: 120px;
      border: 1px solid #dedede;
      border-radius: 4px;
      background-color: #efefef;
      font-size: .8rem;
      padding:3px 0;
      overflow-y: scroll;
    }
  </style>
</head>
<body>
  <div class="wrapper">
    <span id="file-mask">请选择文件</span>
    <input type="file" name="file" id="file" class="sr-only">
    <span id="mime-list"></span>
  </div>
  <script type="text/javascript">
    $(document).ready(function() {
      $("#file-mask").click(function(){
        $('#file').trigger('click');
      });
      $("#file").change(function(){
        var a = $(this)[0].files[0], ext = a.name.substring(a.name.lastIndexOf('.')), mime= a.type;
        $('#mime-list').append('<div class="mime-item"><span>'+ext+'</span><span><span>'+mime+'</span></div>');
      });
    });
  </script>
</body>
</html>

345aa601-2dad-445d-b0e8-20f9d77ed75b.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容