input限制上传文件的类型
如下所示:
《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">
注意:以逗号分隔开

本文详细介绍如何使用HTML的input标签限制上传文件的类型,包括各种常见文件格式如CSV、Excel、图片、HTML、视频、音频及PDF等。通过设置input标签的accept属性,可以有效地控制用户上传的文件类型,提高网站的安全性和用户体验。
1万+

被折叠的 条评论
为什么被折叠?



