English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML reference manual

HTML tag大全

HTML: <input> accept attribute

The accept attribute specifies the filter for the file types that users can select from the file input dialog (only for type ="file"), note: the accept attribute can only be used with <input type ="file">

 HTML <input> etiqueta

Online example

Specify the file types that users can select from the file input dialog:

<!DOCTYPE html>
<html>
<head>
<title>HTML: <input> accept attribute - 基础教程网(oldtoolbag.com)</title>
<body>
<form action="action_page.php">
  <input type="file" name="pic" accept="image/*">
  <input type="submit">
</form>
</body>
</html>
Test to see ‹/›

Browser compatibility

IEFirefoxOperaChromeSafari

Internet Explorer 10, Firefox, Opera, Chrome and Safari 6 Supports the accept attribute.

Note:Internet Explorer 9 Previous versions do not support the accept attribute of the <input> tag.

定义和用法

accept属性为用户可以从文件输入对话框中选择的文件类型指定过滤器(仅用于type ="file")。
注意: accept属性只能与<input type ="file">一起使用。

提示:请勿将此属性用作验证工具。文件上传应在服务器上验证,以保证上传的安全性。

HTML 4.01 与 HTML5之间的差异

没有。

语法

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

提示:如果要指定多个值,请用逗号分隔这些值(比如 <input accept="audio/*,video/*,image/*" />)。

属性值

描述
audio/*接受所有的声音文件。
video/*接受所有的视频文件。
image/*接受所有的图像文件。
MIME_type一个有效的 MIME 类型,不带参数。请参阅 IANA MIME 类型,获取标准 MIME 类型的完整列表。
 HTML <input> etiqueta