如何过滤输入类型=“文件”按特定文件类型对话? [英] How to filter input type="file" dialog by specific file type?

查看:90
本文介绍了如何过滤输入类型=“文件”按特定文件类型对话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击< input type =file> 的浏览按钮时,我想将浏览器限制为JPG文件。



是否可以浏览特定的文件类型? http://www.w3schools.com/tags/att_input_accept.asp

< blockquote>

除了
Internet Explorer和Safari之外,所有主流浏览器都支持accept属性。定义和用法



accept属性指定服务器
接受的文件类型(可通过文件上传提交)。



注意:accept属性只能用于< input type =file>



提示:请勿将此属性用作验证工具。文件上传
应在服务器上进行验证。



语法< input accept =audio / * | video / * | image提示:要指定多个值,请使用逗号分隔
(/ *)例如< input accept =audio / *,video / *,image / */>


I want to restrict the browser to JPG files when I click on browse button of the <input type="file">.

Is it possible to browse for specific file types?

解决方案

See http://www.w3schools.com/tags/att_input_accept.asp:

The accept attribute is supported in all major browsers, except Internet Explorer and Safari. Definition and Usage

The accept attribute specifies the types of files that the server accepts (that can be submitted through a file upload).

Note: The accept attribute can only be used with <input type="file">.

Tip: Do not use this attribute as a validation tool. File uploads should be validated on the server.

Syntax <input accept="audio/*|video/*|image/*|MIME_type" />

Tip: To specify more than one value, separate the values with a comma (e.g. <input accept="audio/*,video/*,image/*" />.

这篇关于如何过滤输入类型=“文件”按特定文件类型对话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆