我找不到有效的 MIME 类型。但是,以下方法确实有效:
<input type="file" accept="application/pdf,.pps" name="upldInput"/>
显然,您可以混合和匹配文件扩展名和 MIME 类型。在 Chrome 25 和 IE 10 (PC) 上,这提供了所需的行为,即仅显示匹配的 MIME 类型或扩展名。
演示:http: //jsfiddle.net/GGFVv/
我也尝试过混合多个扩展和多种 MIME 类型,这似乎也有效。
<input type="file"
accept=".pps,
.jpg,
.txt,
application/pdf,
application/vnd.ms-powerpoint,
application/vnd.openxmlformats-officedocument.presentationml.slideshow,
application/vnd.openxmlformats-officedocument.presentationml.presentation" name="upldInput"/>
Demo: http://jsfiddle.net/GGFVv/2/
I should note that file extension filtering does not seem to work in Firefox 19. I imagine this is because of the differences between the behavior defined by the W3C and the WHATWG.
The original mention of accept
(in 1995!) is somewhat vague:
Allow an ACCEPT attribute for INPUT tag, which is a list of media
types or type patterns allowed for the input.
Firefox appears to default to "all files" when it finds a value it doesn't recognize, so this is somewhat user-friendly (though not ideal).