input type=file accept中可以限制的文件类型
<input type="file" accept="application/msword" ><br><br>accept属性列表<br>
1.accept="application/msexcel"
2.accept="application/msword"
3.accept="application/pdf"
4.accept="application/poscript"
5.accept="application/rtf"
6.accept="application/x-zip-compressed"
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"
这个就可以实现选择具体的数据类型,但是有兼容问题,我在测试的时候只有Opera,Chrome能用,火狐和IE都不兼容
好吧,就在这里测试一下吧:
我只想要word
在这里如果想支持多种类型的话,比如金山的office和microsoft的office的不同扩展名,这样的话可以在accept里面放置多个属性就可以了:
<form> <input type="file" name="pic" id="pic" accept="image/gif, image/jpeg"
/></form>
如果不限制图像的格式,可以写为:accept="image/*"。同样是可以的
好的,测试一下:
我只想要gif、bmp
嗯,测试成功,用Opera,Chrome能用,因为accept也是html5的新特性,所以火狐和IE的支持就显得单薄了,这样还是让我们等待他们的接受把
测试了好久,发现gif和bmp一起的时候并不是能取得他们的并集,仔细观察以后是按写入顺序排列了一下他们的“文件选择类型”:
就像是下面的图片一样:
我们如果不定义input file的格式的时候,那么文件类型的地方就是全部文件*.*,如果我们定义了自己的,那么文件类型就会和我们选中的一样,但是这时候我们如果想看别的文件的时候还是可以通过文件类型的下拉框,去选择自己额外喜欢的类型的,简单的说,它就是起到了一个简单的按照我们的主观意愿筛选的作用,同时我们如果不是选择的image/*而是好几个并列的话就会按照上面的情况分别得排列出来,比如图上的我input就是这个样子的:
<form> <input type="file" name="pic" id="pic" accept="image/gif, image/x-ms-bm
p, image/bmp
"
/></form>
input type=file accept中可以限制的文件类型
在上传文件的时候,需要限制指定的文件类型,accept这个属性,只在FF和chrome中有效。那么accept能限制哪些文件呢?见下表。
扩展名 |
MIME |
描述 |
*.3gpp |
audio/3gpp, video/3gpp |
3GPP Audio/Video |
*.ac3 |
audio/ac3 |
AC3 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 Database |
*.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 |
*.jp2 |
image/jp2 |
JPEG-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 |
*.mp2 |
audio/mpeg, video/mpeg |
MPEG Audio/Video Stream, Layer II |
*.mp3 |
audio/mpeg |
MPEG Audio Stream, Layer III |
*.mp4 |
audio/mp4, video/mp4 |
MPEG-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 Presentation |
*.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 Database |
*.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 |
aplication/zip |
Compressed Archive |
有话要说