<!-- 只显示csv文件 -->
<input id="fileSelect" type="file" accept=".csv" />
<!-- 只显示xlsx文件 -->
<input id="fileSelect" type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
<!-- 只显示xls文件 -->
<input id="fileSelect" type="file" accept="application/vnd.ms-excel" />
<!-- 只显示csv、xls、xlsx文件 -->
<input id="fileSelect" type="file" accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" />
可能会发生的情况:
由于我自己是Mac系统,所以我的xls无法实现效果,但是在Windows和Linux是没有问题的。
可接受的类型:
CSV 文件(.csv),请使用:
<input type="file" accept=".csv" />
或者
<input type="file" accept="text/csv" />
Excel Files 2003-2007 (.xls),请使用:
<input type="file" accept="application/vnd.ms-excel" />
Excel Files 2010 (.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" />