gpt4 book ai didi

javascript - 如何过滤文件输入,使其只显示一种类型的文件?

转载 作者:太空宇宙 更新时间:2023-11-03 21:34:55 25 4
gpt4 key购买 nike

如何过滤文件输入,使其只显示一种类型的文件?我试过了,但没用:

<input type="file" value="*.docx"/>

最佳答案

有一个accept您可以添加到 <input> 的属性元素只允许浏览某些文件扩展名:

<input type="file" value="*.docx" accept=".doc,.docx" />

引用 - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input

If the value of the type attribute is file, this attribute indicates the types of files that the server accepts; otherwise it is ignored. The value must be a comma-separated list of unique content type specifiers:

  • A file extension starting with the STOP character (U+002E). (E.g.: ".jpg,.png,.doc")
  • ...

请记住,绕过此“限制”非常容易,任何具有最少 HTML 知识的人都可以通过在单击浏览按钮之前修改页面上的实际 HTML 元素来浏览和选择“不受支持”的文件类型.

关于javascript - 如何过滤文件输入,使其只显示一种类型的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27212559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com