js上傳文件限制文件的類型

做後臺管理需要限制上傳文件的類型;具體做法如下所示:

《1》上傳.csv格式的

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

《2》上傳.xls格式

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

《3》上傳.xslx格式

<input text="fiel" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"/>

《4》上傳.png/.jpg/etc格式

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

《5》上傳圖片格式

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

《6》上傳.htm,.html格式

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

《7》上傳video(.avi, .mpg, .mpeg, .mp4)格式

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

《8》上傳audio(.mp3, .wav, etc)格式

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

《9》上傳.pdf格式

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

《10》如果限制兩種文件格式,同時限制

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

注意:以逗號分隔開

發佈了55 篇原創文章 · 獲贊 24 · 訪問量 13萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章