从 HTML 文件输入中删除“所有文件"选项 [英] Remove 'All Files' option from HTML file input

查看:33
本文介绍了从 HTML 文件输入中删除“所有文件"选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 上传音频文件.

I am using <input type="file"> to upload audio files.

为此,我使用了 accept="audio/*".因此,浏览器的文件选择对话框默认只显示音频文件.但是,该对话框中有一个我不想要的名为所有文件"的选项.

To do that I am using accept="audio/*". Because of this, the browser's file-select dialog shows only audio files by default. However, there is an option called "All Files" in that dialog box that I don't want.

(注意 - 也欢迎使用 Javascript、jQuery 和 AngularJs 中的任何解决方案)

(note - Any solution in Javascript , jQuery and AngularJs is also welcome)

如何禁用/删除所有文件"选项?

How can I disable/remove the "All Files" option?

推荐答案

我认为这超出了浏览器的范围,更多取决于操作系统.然而,不管情况如何,我认为无论如何都不应该把这件事搞砸.

I believe that this is outside the scope of the browser, and is more up to the OS. However, despite whatever the case is, I don't think that this is something that you should mess with anyway.

accept 没有最好的支持(虽然可能不是问题),但正如您在此处看到的:http://www.iana.org/assignments/media-types/media-types.xhtml#audio无论如何,允许的类型可能不在您的应用程序范围内.您应该做的最好的事情是执行服务器端验证,使用 accept 纯粹作为客户端指示器.

accept doesn't have the best support (although might not be an issue), but as you can see here: http://www.iana.org/assignments/media-types/media-types.xhtml#audio the sheer number of allowed types probably falls outside of the scope of your application anyway. The best thing you should do is perform server side validation, using accept purely as a client indicator.

此外,虽然这是一个较旧的答案,但我认为它仍然相关且有效:文件输入'接受'属性 - 有用吗?

Also, while it is an older answer, I think it is still relevant and valid: File input 'accept' attribute - is it useful?

这篇关于从 HTML 文件输入中删除“所有文件"选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆