input的file类型的accept属性的值
属性值
值描述
audio/*接受所有的声⾳⽂件。
video/*接受所有的视频⽂件。
image/*接受所有的图像⽂件。
MIME_type⼀个有效的 MIME 类型,不带参数。请参阅 ,获得标准 MIME 类型的完整列表。
在上传⽂件的时候,需要限制指定的⽂件类型,accept这个属性,只在FF和chrome中有效。那么accept能限制哪些⽂件呢?见下表。扩展名 MIME 描述
摘抄150字
*.3gpp audio/3gpp, video/3gpp3GPP Audio/Video
*.ac3audio/ac3AC3 Audio
*.asf allpication/vnd.ms-asf Advanced Streaming Format
*.au audio/basic AU Audio
*.css text/css Cascading Style Sheets
*.csv text/csv Comma Separated Values
*.doc application/msword MS Word Document
*.dot application/msword MS Word Template
优美的句子摘抄*.dtd application/xml-dtd Document Type Definition
*.dwg image/vnd.dwg AutoCAD Drawing Databa
*.dxf image/vnd.dxf AutoCAD Drawing Interchange Format
*.gif image/gif Graphic Interchange Format
*.htm text/html HyperText Markup Language
*.html text/html HyperText Markup Language
*.jp2image/jp2JPEG-2000
*.jpe image/jpeg JPEG
*.jpeg image/jpeg JPEG
一个半小时英文*.jpg image/jpeg JPEG
*.js text/javascript, application/javascript JavaScript
幕府*.json application/json JavaScript Object Notation
*.mp2audio/mpeg, video/mpeg MPEG Audio/Video Stream, Layer II
*.mp3audio/mpeg MPEG Audio Stream, Layer III
*.mp4audio/mp4, video/mp4MPEG-4 Audio/Video
*.mpeg video/mpeg MPEG Video Stream, Layer II
*.mpg video/mpeg MPEG Video Stream, Layer II
*.mpp application/vnd.ms-project MS Project Project
*.ogg application/ogg, audio/ogg Ogg Vorbis
*.pdf application/pdf Portable Document Format
*.png image/png Portable Network Graphics
*.pot application/vnd.ms-powerpoint MS PowerPoint Template
*.pps application/vnd.ms-powerpoint MS PowerPoint Slideshow
*.ppt application/vnd.ms-powerpoint MS PowerPoint Prentation
*.rtf application/rtf, text/rtf Rich Text Format
辞职怎么说
*.svf image/vnd.svf Simple Vector Format
*.tif image/tiff Tagged Image Format File
*.tiff image/tiff Tagged Image Format File
*.txt text/plain Plain Text
*.wdb application/vnd.ms-works MS Works Databa
*.wps application/vnd.ms-works Works Text Document
*.xhtml application/xhtml+xml Extensible HyperText Markup Language *.xlc application/vnd.ms-excel MS Excel Chart
*.xlm application/vnd.ms-excel MS Excel Macro
*.xls application/vnd.ms-excel MS Excel Spreadsheet
*.xlt application/vnd.ms-excel MS Excel Template
*.xlw application/vnd.ms-excel MS Excel Workspace
*.xml text/xml, application/xml Extensible Markup Language
*.zip application/zip Compresd Archive
实例 :
1.accept="image/gif, image/jpeg"
2.accept="application/msword"
3.accept="application/pdf"
4.accept="application/poscript"
5.accept="application/rtf"
6.accept="application/x-zip-compresd"
7.accept="audio/basic"
8.accept="audio/x-aiff"
9.accept="audio/x-mpeg"
10.accept="audio/x-pn/realaudio"汽车燃油泵
11.accept="audio/x-waw"
12.accept="image/gif"
减肥方法七天瘦十斤
13.accept="image/jpeg"
14.accept="image/tiff"
15.accept="image/x-ms-bmp"
16.accept="image/x-photo-cd"
17.accept="image/x-png"
18.accept="image/x-portablebitmap"
19.accept="image/x-portable-greymap"
20.accept="image/x-portable-pixmap"
21.accept="image/x-rgb"
22.accept="text/html"
23.accept="text/plain"
24.accept="video/quicktime"
25.accept="video/x-mpeg2"
26.accept="video/x-msvideo"
office办公软件2007以后版本各⽂档的后缀名,如docx、xlsx
Extension MIME Type
.xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xltx application/vnd.plate
.potx application/vnd.plate
.ppsx application/vnd.openxmlformats-officedocument.prentationml.slideshow
.pptx application/vnd.openxmlformats-officedocument.prentationml.prentation
.
sldx application/vnd.openxmlformats-officedocument.prentationml.slide
.docx application/vnd.openxmlformats-officedocument.wordprocessingml.document
.dotx application/vnd.plate
.xlsm application/vnd.ms-excel.addin.macroEnabled.12
.xlsb application/vnd.ms-excel.sheet.binary.macroEnabled.12
如果你不希望⽤户上传任何类型的⽂件, 你可以使⽤ input 的 accept 属性.
设置⽀持 .doc / .docx / .xls / .xlsx / .pdf 格式:梦见倒垃圾
<input type="file"accept=".doc,.docx,.xls,.xlsx,.pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document">
如果需要⽀持 .png 等,则在 accept 添加上既可,都逗号分隔。
扩展知识:
accept 属性接受⼀个逗号分隔的 MIME 类型字符串, 如:
accept="image/png" or accept=".png" — 只接受 png 图⽚.
accept="image/png, image/jpeg" or accept=".png, .jpg, .jpeg" — PNG/JPEG ⽂件.
accept="image/*" — 接受任何图⽚⽂件类型.
accept=".doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document" — 接受任何 MS Doc ⽂件类型.
<input> type 类型为 file 的 input 元素使得⽤户可以选择⼀个或多个元素以提交表单的⽅式上传到服务器上,或者通过 Javascript 的 File API 对⽂件进⾏操作