Html 输入元素的“接受”属性不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2505334/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
'Accept' attribute of input element is not working
提问by subash
I came across a browse file dialog-control tag in html and the tag was
我在 html 中遇到了一个浏览文件对话框控件标签,该标签是
<input id="myfile" name="myfile" type="file" accept="application/pdf"/>
but the 'accept' attribute doesn't seems to have any effect. I am using Internet Explorer 8.
但“接受”属性似乎没有任何效果。我正在使用 Internet Explorer 8。
回答by ghermeto
according to the w3schools (http://www.w3schools.com/TAGS/att_input_accept.asp), the 'accept' attribute is not properly supported by any of the major browsers. The filter inside the file browser dialog will not work.
根据 w3schools ( http://www.w3schools.com/TAGS/att_input_accept.asp),任何主要浏览器都没有正确支持“accept”属性。文件浏览器对话框内的过滤器将不起作用。
You could use a javascript validation on the form onsubmit event to verify if the file type is correct, returning false otherwise.
您可以在表单 onsubmit 事件上使用 javascript 验证来验证文件类型是否正确,否则返回 false。
回答by David Flamme
It seems like browsers have trouble following the IANA specifications found here: http://www.iana.org/assignments/media-types/media-types.xhtml
浏览器似乎无法遵循此处找到的 IANA 规范:http: //www.iana.org/assignments/media-types/media-types.xhtml
In my case, the application/pkcs* media types don't work at all, while for some reason application/x-pkcs12 works in chrome and partially(.p12) in IE. Firefox seems completely oblivious.
就我而言, application/pkcs* 媒体类型根本不工作,而由于某种原因 application/x-pkcs12 在 chrome 中工作,在 IE 中部分(.p12)工作。Firefox 似乎完全没有注意到。
I also found this more optimistic discussion over here. File input 'accept' attribute - is it useful?
我也在这里找到了更乐观的讨论。文件输入“接受”属性 - 有用吗?
So, the best description would be "probably unsupported for uncommon formats", and with the x-pkcs vs pkcs confusion more or less unusable in my case.
因此,最好的描述是“可能不支持不常见的格式”,并且在我的情况下,x-pkcs 与 pkcs 混淆或多或少无法使用。