作为程序员一定要保持良好的睡眠,才能好编程

html input="file" 浏览时只显示指定文件类型

发布时间:2019-01-09

Valid Accept Types:

For CSV files (.csv), use: 


<input id="fileSelect" type="file" accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" />   

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


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

For Excel Files 2010 (.xlsx), use: 


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

For Text Files (.txt) use: 


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

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


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

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


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

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


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

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


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

For PDF Files, use:


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