如何制作< input type ="档案" />只接受这些类型? [英] How to make <input type="file"/> accept only these types?
问题描述
我希望我的上传者只允许这些类型: 编辑!!! 我还有一个要问的事情。当出现用于选择文件的弹出窗口时,在右下角有一个包含所有允许文件的下拉列表。就我而言,名单会很长。我在列表中看到,有一个名为 任何帮助将不胜感激。谢谢。
接受
属性放在什么位置?感谢您的帮助。
所有支持的类型
的选项。我怎样才能使它在默认情况下被选中,并消除所有其他选项?
accept
属性是按照HTML5 LC,用逗号分隔的项目列表,每个项目是像 image / gif
这样的特殊媒体类型,或者像 image / *
这样的符号,指的是所有的 image
类型,或者像 .gif
这样的文件扩展名。 IE 10+和Chrome支持所有这些,而Firefox不支持这些扩展。因此,最安全的方法是使用媒体类型和符号如 image / *
,在这种情况下
< input type =filename = fooaccept =
application / msword,application / vnd.ms-excel,application / vnd.ms-powerpoint,
text / plain,application / pdf,image / *>预亦当亦作读亦读预读中的信息信息信息范范信息范范信息范范内预期请注意,浏览器可能无法完全识别权威注册表中指定的媒体类型名称,因此需要进行一些测试。
I want my uploader only allows these types:
- doc, docx.
- xls, xlsx.
- ppt, pptx.
- txt.
- pdf.
- Image types.
How can I achieve this? What should I put in the accept
attribute? Thanks for your help.
EDIT!!!
I have one more thing to ask. When the popup appears for use to choose file, at the down right corner, there is a drop down list contains all allow files. In my case, the list would be long. I see in the list, there is an option called All Supported Types
. How can I make it chosen by default and eliminate all other options?
Any help will be appreciated. Thank you.
The value of the accept
attribute is, as per HTML5 LC, a comma-separated list of items, each of which is a specific media type like image/gif
, or a notation like image/*
that refers to all image
types, or a filename extension like .gif
. IE 10+ and Chrome support all of these, whereas Firefox does not support the extensions. Thus, the safest way is to use media types and notations like image/*
, in this case
<input type="file" name="foo" accept=
"application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint,
text/plain, application/pdf, image/*">
if I understand the intents correctly. Beware that browsers might not recognize the media type names exactly as specified in the authoritative registry, so some testing is needed.
这篇关于如何制作< input type ="档案" />只接受这些类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!