html input="file" 瀏覽時只顯示指定文件類型 xls、xlsx、csv

Valid Accept Types:

For CSV files (.csv), use: 
html

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

For Excel Files 2003-2007 (.xls), use: 
app

<input type="file" accept="application/vnd.ms-excel" />

For Excel Files 2010 (.xlsx), use: 
ide

<input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />

For Text Files (.txt) use: 
this

<input type="file" accept="text/plain" />

For Image Files (.png/.jpg/etc), use: 
spa

<input type="file" accept="image/*" />

For HTML Files (.htm,.html), use:
.net

<input type="file" accept="text/html" />

For Video Files (.avi, .mpg, .mpeg, .mp4), use:excel

<input type="file" accept="video/*" />

For Audio Files (.mp3, .wav, etc), use:code

<input type="file" accept="audio/*" />

For PDF Files, use:orm

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

DEMO:
http://jsfiddle.net/dirtyd77/LzLcZ/144/xml


NOTE:

If you are trying to display Excel CSV files (.csv), do NOT use:

  • text/csv

  • application/csv

  • text/comma-separated-values (works in Opera only).


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" />
相關文章
相關標籤/搜索