我的页面上有一个文件上传对象:
<input type="file" ID="fileSelect" />
在我的桌面上使用以下excel文件:
- file1.xlsx
- file1.xls
- file.csv
我要上传文件到ONLY显示.xlsx
,.xls
,和.csv
文件。
使用accept
属性,我发现这些内容类型负责.xlsx
&.xls
扩展...
accept
= application / vnd.openxmlformats-officedocument.spreadsheetml.sheet(.XLSX)
accept
= application / vnd.ms-excel(.XLS)
但是,我找不到Excel CSV文件的正确内容类型!有什么建议么?
好吧,这很尴尬。。。我找到了我想要的解决方案,而且再简单不过了。我使用以下代码来获得所需的结果。希望这对以后的人有所帮助。感谢大家的帮助。
<input id="fileSelect" type="file" accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" />
对于CSV文件(.csv),请使用:
<input type="file" accept=".csv" />
对于Excel文件97-2003(.xls),请使用:
<input type="file" accept="application/vnd.ms-excel" />
对于Excel Files 2007+(.xlsx),请使用:
<input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
对于文本文件(.txt),请使用:
<input type="file" accept="text/plain" />
对于图像文件(.png / .jpg / etc),请使用:
<input type="file" accept="image/*" />
对于HTML文件(.htm,.html),请使用:
<input type="file" accept="text/html" />
对于视频文件(.avi,.mpg,.mpeg,.mp4),请使用:
<input type="file" accept="video/*" />
对于音频文件(.mp3,.wav等),请使用:
<input type="file" accept="audio/*" />
对于PDF文件,请使用:
<input type="file" accept=".pdf" />
演示:http :
//jsfiddle.net/dirtyd77/LzLcZ/144/
注意:
如果您试图显示Excel CSV文件(.csv
),请不要使用:
text/csv
application/csv
text/comma-separated-values
(仅适用于Opera)。如果您尝试显示特定的文件类型(例如aWAV
或PDF
),那么这几乎总是可行的...
<input type="file" accept=".FILETYPE" />
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句