---
title: "上传文件如何在打开对话框中只显示指定后缀的文件"
author: "daoshud1"
date: "2013-04-17T19:25:08Z"
tags: []
categories: ["Web前端"]
slug: "untitled"
draft: false
lastmod: "2013-04-17T19:25:08Z"
id: 1849096
url: "https://daoshud1.iteye.com/blog/1849096"
---

例如:文件上传时，选择浏览，这时弹出一个选择文件的对话框。我要让这个对话框里面只显示指定后缀的文件，例如*.xml，请大家帮助解决在html页面中如何指定对话框显示的后缀文件？
可以使用accept属性
<input type="file" accept="image/gif, image/jpeg" >
如果不限制图像的格式，可以写为：accept="image/*"。
accept：MIME_type 用逗号隔开的 MIME 类型列表。
HTML <input> 标签的 accept 属性<http://www.w3school.com.cn/tags/att_input_accept.asp>