<input id="fileId1" type="file" accept="image/png,image/gif" name="file" />
后缀名 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 *.dxfimage/vnd.dxf*.gif image/gif *.htm text/html *.html text/html *.jp2 image/jp2 *.jpe image/jpeg*.jpeg image/jpeg*.jpgimage/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 *.xlcapplication/vnd.ms-excel *.xlm application/vnd.ms-excel *.xls application/vnd.ms-excel *.xltapplication/vnd.ms-excel *.xlwapplication/vnd.ms-excel *.xml text/xml, application/xml *.zip aplication/zip *.xlsxapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet
转载自:/post/input_file_leixing
实践补充:
1.对于zip文件类型的判断,accept属性可以接受.zip,写成
accept='.zip'
然而如果要通过文件的type字段来比较的话,应该写成
file.type === 'application/x-zip-compressed'
2.对于excel类型文件的判断,accept属性可以接受如下:
accept='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel'