網(wǎng)頁上添加一個input file HTML控件:
1<input?id="File1" type="file" />
默認是這樣的,所有文件類型都會顯示出來印蓖,如果想限制它只顯示我們設(shè)定的文件類型呢旗闽,比如“word“,”excel“,”pdf“文件
解決辦法是可以給它添加一個accept屬性,比如:
1<input?id="File1" type="file"? accept=".xls,.doc,.txt,.pdf"? />
這樣選擇的時候默認會顯示為這樣:
文件選擇框內(nèi)只顯示出你自定義文件類型的文件蜡塌,也還比較方便碉纳。
But,這只是最簡單的掩人耳目的做法,還是能選擇其它文件類型:
所以岗照,如果要做到真正意義上限制類型做法(其實這種算不上限制村象,只是把你要的文件類型默認顯示出來而已,并不是說不能選擇其它的)攒至,還是要通過js或者后臺來控制厚者。
附支持的文件類型:
01:*.3gpp audio/3gpp, video/3gpp 3GPP Audio/Video
02:*.ac3? audio/ac3? AC3 Audio
03:*.asf? allpication/vnd.ms-asf? Advanced Streaming Format
04:*.au? ? audio/basic AU Audio
05:*.css? text/css? ? Cascading Style Sheets
06:*.csv? text/csv? ? Comma Separated Values
07:*.doc? application/msword? MS Word Document
08:*.dot? application/msword? MS Word Template
09:*.dtd? application/xml-dtd Document Type Definition
10:*.dwg? image/vnd.dwg? AutoCAD Drawing Database
11:*.dxf? image/vnd.dxf? AutoCAD Drawing Interchange Format
12:*.gif? image/gif? Graphic Interchange Format
13:*.htm? text/html? HyperText Markup Language
14:*.html? text/html? HyperText Markup Language
15:*.jp2? image/jp2? JPEG-2000
16:*.jpe? image/jpeg? JPEG
17:*.jpeg? image/jpeg? JPEG
18:*.jpg? image/jpeg? JPEG
19:*.js? ? text/javascript迫吐, application/javascript JavaScript
20:*.json? application/json? ? JavaScript Object Notation
21:*.mp2? audio/mpeg库菲, video/mpeg? MPEG Audio/Video Stream, Layer II
22:*.mp3? audio/mpeg? MPEG Audio Stream志膀, Layer III
23:*.mp4? audio/mp4熙宇, video/mp4? ? MPEG-4 Audio/Video
24:*.mpeg? video/mpeg? MPEG Video Stream鳖擒, Layer II
25:*.mpg? video/mpeg? MPEG Video Stream, Layer II
26:*.mpp? application/vnd.ms-project? MS Project Project
27:*.ogg? application/ogg烫止, audio/ogg? Ogg Vorbis
28:*.pdf? application/pdf Portable Document Format
29:*.png? image/png? Portable Network Graphics
30:*.pot? application/vnd.ms-powerpoint? MS PowerPoint Template
31:*.pps? application/vnd.ms-powerpoint? MS PowerPoint Slideshow
32:*.ppt? application/vnd.ms-powerpoint? MS PowerPoint Presentation
33:*.rtf? application/rtf蒋荚, text/rtf? Rich Text Format
34:*.svf? image/vnd.svf? Simple Vector Format
35:*.tif? image/tiff? Tagged Image Format File
36:*.tiff? image/tiff? Tagged Image Format File
37:*.txt? text/plain? Plain Text
38:*.wdb? application/vnd.ms-works? ? MS Works Database
39:*.wps? application/vnd.ms-works? ? Works Text Document
40:*.xhtml application/xhtml+xml? Extensible HyperText Markup Language
41:*.xlc? application/vnd.ms-excel? ? MS Excel Chart
42:*.xlm? application/vnd.ms-excel? ? MS Excel Macro
43:*.xls? application/vnd.ms-excel? ? MS Excel Spreadsheet
44:*.xlt? application/vnd.ms-excel? ? MS Excel Template
45:*.xlw? application/vnd.ms-excel? ? MS Excel Workspace
46:*.xml? text/xml, application/xml? Extensible Markup Language
57:*.zip? aplication/zip? Compressed Archiveinput file控件限制上傳文件類型 - Kenyep - 博客園