在我的桌面上使用以下excel文件:..."> 在我的桌面上使用以下excel文件:..."/> 在我的桌面上使用以下excel文件:..."> 在我的桌面上使用以下excel文件:...">

HTML Input =“ file”接受属性文件类型(CSV)

html HTML

樱凯Mandy

2020-03-19

我的页面上有一个文件上传对象:

<input type="file" ID="fileSelect" />

在我的桌面上使用以下excel文件:

  1. file1.xlsx
  2. file1.xls
  3. 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文件的正确内容类型!有什么建议么?

示例:http//jsfiddle.net/LzLcZ/

第2359篇《HTML Input =“ file”接受属性文件类型(CSV)》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

5个回答
伽罗前端 2020.03.19

现在,您可以使用新的html5输入验证属性pattern=".+\.(xlsx|xls|csv)"

小小 2020.03.19

好吧,这很尴尬。。。我找到了我想要的解决方案,而且再简单不过了。我使用以下代码来获得所需的结果。希望这对以后的人有所帮助。感谢大家的帮助。

<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)。

If you are trying to display a particular file type (for example, a WAV or PDF), then this will almost always work...

 <input type="file" accept=".FILETYPE" />
古一神乐 2020.03.19

我已经text/comma-separated-values在接受属性中使用了CSV mime-type,并且在Opera中工作正常。尝试text/csv没有运气。

如果建议的其他MIME类型为CSV,则为CSV:

  • 文字/逗号分隔值
  • 文字/ csv
  • 应用程序/ csv
  • 应用程序/ excel
  • 应用程序/vnd.ms-excel
  • 应用程序/ vnd.msexcel
  • 文字/任何文字

来源:http//filext.com/file-extension/CSV

村村伽罗十三 2020.03.19

在Safari 10下,这对我不起作用:

<input type="file" accept=".csv" />

我不得不这样写:

<input type="file" accept="text/csv" />
米亚LEY 2020.03.19

这些天你可以只使用文件扩展名

<input type="file" ID="fileSelect" accept=".xlsx, .xls, .csv"/>

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android