详解 input accept属性

input accept属性是用来限制上传的文件格式

 <input type="file" id="file" style="display:none;"
                accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
<a href="javascript:selectFile()">加载本地excel文件</a>
function selectFile() {
            document.getElementById('file').click();
        }
  • 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">
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章