文件上传input type=“file”的accept接收的各种文件类型总结

前言

        前端选择文件时,都会使用 input 框设定 type="file" 来选择文件,默认情况下可以选择所有类型的文件,有时候需要限定选择的文件类型,这时候就用到了 accept 属性。

        ps:accept 属性仅适用于 <input type="file"/>

accept 各种类型

文件类型accept 属性值(多个值之间以逗号隔开)
.3gppaudio/3gpp, video/3gpp
.ac3audio/ac3
.asfallpication/vnd.ms-asf
.auaudio/basic
.csstext/css
.csvtext/csv
.docapplication/msword
.docxapplication/vnd.openxmlformats-officedocument.wordprocessingml.document
.dotapplication/msword
.dotxapplication/vnd.openxmlformats-officedocument.wordprocessingml.template
.docmapplication/vnd.ms-word.document.macroEnabled.12
.dotmapplication/vnd.ms-word.template.macroEnabled.12
.dtdapplication/xml-dtd
.dwgimage/vnd.dwg
.dxfimage/vnd.dxf
.gifimage/gif
.htmtext/html
.htmltext/html
.jp2image/jp2
.jpeimage/jpeg
.jpegimage/jpeg
.jpgimage/jpeg
.jstext/javascript, application/javascript
.jsonapplication/json
.mp2audio/mpeg, video/mpeg
.mp3audio/mpeg
.mp4audio/mp4, video/mp4
.mpegvideo/mpeg
.mpgvideo/mpeg
.mppapplication/vnd.ms-project
.oggapplication/ogg, audio/ogg
.pdfapplication/pdf
.pngimage/png
.potapplication/vnd.ms-powerpoint
.potmapplication/vnd.ms-powerpoint.presentation.macroEnabled.12
.potxapplication/vnd.openxmlformats-officedocument.presentationml.template
.ppsapplication/vnd.ms-powerpoint
.ppsmapplication/vnd.ms-powerpoint.slideshow.macroEnabled.12
.ppsxapplication/vnd.openxmlformats-officedocument.presentationml.slideshow
.pptapplication/vnd.ms-powerpoint
.pptmapplication/vnd.ms-powerpoint.presentation.macroEnabled.12
.pptxapplication/vnd.openxmlformats-officedocument.presentationml.presentation
.ppaapplication/vnd.ms-powerpoint
.ppamapplication/vnd.ms-powerpoint.addin.macroEnabled.12
.rtfapplication/rtf, text/rtf
.svfimage/vnd.svf
.tifimage/tiff
.tiffimage/tiff
.txttext/plain
.wdbapplication/vnd.ms-works
.wpsapplication/vnd.ms-works
.xhtmlapplication/xhtml+xml
.xlcapplication/vnd.ms-excel
.xlmapplication/vnd.ms-excel
.xlaapplication/vnd.ms-excel
.xlamapplication/vnd.ms-excel.addin.macroEnabled.12
.xlsapplication/vnd.ms-excel
.xlsxapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xlsmapplication/vnd.ms-excel.sheet.macroEnabled.12
.xlsbapplication/vnd.ms-excel.sheet.binary.macroEnabled.12
.xltapplication/vnd.ms-excel
.xltxapplication/vnd.openxmlformats-officedocument.spreadsheetml.template
.xltmapplication/vnd.ms-excel.template.macroEnabled.12
.xlwapplication/vnd.ms-excel
.xmltext/xml, application/xml
.zipapplication/zipapplication/x-zip-compressed

        当然,也可以使用 * 指定所有的文件类型,比如:“*” 指定所有文件类型;“image/*” 指定所有图片类型;“audio/*” 或 “video/*” 指定所有视频类型。

用法

<input type="file" accept="image/*,video/*" />

参考:https://blog.youkuaiyun.com/millia/article/details/134200983

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值