IE11 input type="file" accept=".xls" 出现附加分类

IE11 input type="file" accept=".xls" additional categories appear

在 IE11 中,每当我在输入中使用 accept 属性时,除了通常的 "All files" 和 "Custom files(.xls) there's two additional categories appear: "Images" 和 "HTML"。有没有办法删除不需要的类别?

可以在任何具有 accept 属性的输入处为我重现该问题,例如在这个 JSFiddle 中:http://jsfiddle.net/sachinjoseph/BkcKQ/

IE 10+, Edge, Chrome:<br />
<label>.xls,.xlsx files</label>
<input type="file" accept=".xls,.xlsx" />
<br />
<br />
IE 10+, Edge, Chrome, Firefox:<br />
<label>.xls,.xlsx files (using MIME-types)</label>
<input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel" />
<br />
<br />
<h3>
Recommended way of achieving file type filter:
</h3>
IE 10+, Edge, Chrome, Firefox:<br />
<label>.xls,.xlsx files (using both extensions and MIME-types)</label>
<input type="file"
     accept=".xls,.xlsx, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel" />
<br />
<br /> <br />
<br />
    <b>Note:</b><p>Edge allows to choose files of any type by default, even if accept attribute is set, although it adds a custom filter list to the file-select dialog box. The user must manually apply the filter from the file-select dialog box.</p>

IE 通常不符合标准。 HTML 标准允许 mime 类型以及文件扩展名以句号开头。相比之下,IE 的 accept 属性规范只提到了 mime 类型。官方规范是这样说的:

The accept attribute may be specified to provide user agents with a hint of what file types will be accepted.

If specified, the attribute must consist of a set of comma-separated tokens, each of which must be an ASCII case-insensitive match for one of the following:

  • The string "audio/*"
    Indicates that sound files are accepted.
  • The string "video/*"
    Indicates that video files are accepted.
  • The string "image/*"
    Indicates that image files are accepted.
  • A valid MIME type with no parameters
    Indicates that files of the specified type are accepted.
  • A string whose first character is a U+002E FULL STOP character (.)
    Indicates that files with the specified file extension are accepted.

来源:
- https://html.spec.whatwg.org/multipage/input.html#attr-input-accept
- https://msdn.microsoft.com/en-us/library/ms533060%28v=vs.85%29.aspx
- File input 'accept' attribute - is it useful?