組合上傳 CSV 和 Excel 文件:
<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" />
注意:
如果您試圖顯示Excel CSV文件(.csv),請不要使用:
text/csv
application/csv
text/comma-separated-values(僅適用於Opera)。
如果您嘗試顯示特定的文件類型(例如 WAV或PDF),那么這幾乎總是可行的...
<input type="file" accept=".FILETYPE" />
原地址: https://stackoverflow.com/questions/11832930/html-input-file-accept-attribute-file-type-csv