zoukankan      html  css  js  c++  java
  • input type="file" 的一些问题

    file可以上传文件,但通常 情况下大家都会需要设置文件上传的格式

    上传文件的格式由一个 accept 属性来控制 列如:

    <input type="file" id="file" accept="application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"  name="uploadFile"/>

    上面这个是只可以上传excel 表格限制的设置方式,两个格式之间用 , 隔开

    常用的一些类型

    后缀名       MIME名称
    *.3gpp    audio/3gpp, video/3gpp
    *.ac3    audio/ac3
    *.asf       allpication/vnd.ms-asf
    *.au           audio/basic
    *.css           text/css
    *.csv           text/csv
    *.doc    application/msword    
    *.dot    application/msword    
    *.dtd    application/xml-dtd    
    *.dwg    image/vnd.dwg    
    *.dxf      image/vnd.dxf
    *.gif            image/gif    
    *.htm    text/html    
    *.html    text/html    
    *.jp2            image/jp2    
    *.jpe       image/jpeg
    *.jpeg    image/jpeg
    *.jpg          image/jpeg    
    *.js       text/javascript, application/javascript    
    *.json    application/json    
    *.mp2    audio/mpeg, video/mpeg    
    *.mp3    audio/mpeg    
    *.mp4    audio/mp4, video/mp4    
    *.mpeg    video/mpeg    
    *.mpg    video/mpeg    
    *.mpp    application/vnd.ms-project    
    *.ogg    application/ogg, audio/ogg    
    *.pdf    application/pdf    
    *.png    image/png    
    *.pot    application/vnd.ms-powerpoint    
    *.pps    application/vnd.ms-powerpoint    
    *.ppt    application/vnd.ms-powerpoint    
    *.rtf            application/rtf, text/rtf    
    *.svf           image/vnd.svf    
    *.tif         image/tiff    
    *.tiff       image/tiff    
    *.txt           text/plain    
    *.wdb    application/vnd.ms-works    
    *.wps    application/vnd.ms-works    
    *.xhtml    application/xhtml+xml    
    *.xlc      application/vnd.ms-excel    
    *.xlm    application/vnd.ms-excel    
    *.xls           application/vnd.ms-excel    
    *.xlt      application/vnd.ms-excel    
    *.xlw      application/vnd.ms-excel    
    *.xml    text/xml, application/xml    
    *.zip            aplication/zip    
    *.xlsx     application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

    file文件里面还有一个重要的属性 required 设置未上传文件时不能上传,建议只有一个提交按钮时使用,如果有两个按钮,只需限制其中一个时候,可以使用
    js来完成
    html:

    <form action="#" th:action="@{/hosts}" method="post" enctype="multipart/form-data" class="hostform">
    <input type="file" id="file" accept="application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" name="uploadFile"/>
    <input type="submit" value="导入" name="import" class="imp"/>
    <input type="submit" value="导出" name="export"/>
    <br><br>
    </form>

    js:

    $(".imp").attr({"disabled":"disabled"});
    var file = $("#file").val();
    $("#file").change(function(){
    if (file == null||file == ""){
    $(".imp").removeAttr("disabled");
    return;
    }
    })

    这里使用到了disabled 属性 ,它是用来禁用input  ,注 disabled属性无法与<input type="hidden">一起使用



    本文为本人用来记录自己做的一些东西,如有不对的地方,请见谅。    你是我支撑下去的理由
  • 相关阅读:
    归并排序(Merge Sort)
    AtCoder AGC035D Add and Remove (状压DP)
    AtCoder AGC034D Manhattan Max Matching (费用流)
    AtCoder AGC033F Adding Edges (图论)
    AtCoder AGC031F Walk on Graph (图论、数论)
    AtCoder AGC031E Snuke the Phantom Thief (费用流)
    AtCoder AGC029F Construction of a Tree (二分图匹配)
    AtCoder AGC029E Wandering TKHS
    AtCoder AGC039F Min Product Sum (容斥原理、组合计数、DP)
    AtCoder AGC035E Develop (DP、图论、计数)
  • 原文地址:https://www.cnblogs.com/xiaorong-9/p/6074180.html
Copyright © 2011-2022 走看看