【问题标题】:how to exclude only file types .doc,.docx,.txt and .rtf file types on file dialog如何在文件对话框中仅排除文件类型 .doc、.docx、.txt 和 .rtf 文件类型
【发布时间】:2019-03-14 22:14:02
【问题描述】:

我尝试使用输入 type="file" 的接受和接受来将字符串设置为 ".doc,.docx,.txt,.rtf" 但它仍然显示 .csv.js 和 .spec.js 文件

<input type="file"
accept=".doc,.docx,.txt,.rtf"./>

添加屏幕截图,这恰好只在 chrome 上

【问题讨论】:

  • 不,不是...我确实使用了接受,但我仍然看到未过滤的文件,例如 js 和 .spec.js 以及日志文件
  • 即使使用 SO 的 sn-p 作为测试,您也会看到错误的文件?嗯,这很奇怪,因为我在 FF、Chrome 和 IE 中进行了测试,但仍然只能看到相应的文件。
  • 它不显示除.doc,.docx,.txt,.rtf 之外的任何其他文件。如果有问题,您可以添加屏幕截图吗?
  • 添加截图

标签: javascript html


【解决方案1】:

问题是accept参数使用的是MIME Type,所以可能不起作用.doc 对不同版本使用 MIME 类型:

.doc application/msword .dot application/msword 
.docx application/vnd.openxmlformats-officedocument.wordprocessingml.document 
.dotx application/vnd.openxmlformats-officedocument.wordprocessingml.template 
.docm application/vnd.ms-word.document.macroEnabled.12 
.dotm application/vnd.ms-word.template.macroEnabled.12

如果需要其他类型https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-17
    • 1970-01-01
    • 2016-02-17
    • 2012-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多