【问题标题】:What is the purpose of webkitRelativePath property in File object?File 对象中 webkitRelativePath 属性的用途是什么?
【发布时间】:2012-01-12 12:48:16
【问题描述】:

如果您在 Chrome 控制台中使用以下简单的方法打印出 File 对象:

<input type="file" onchange="console.info(this.files);" />

您将在其他属性中看到一个始终为空的 webkitRelativePath 属性:

fileName: "07.png"
fileSize: 33022
lastModifiedDate: Date
name: "07.png"
size: 33022
type: "image/png"
webkitRelativePath: ""
__proto__: File

它的目的是什么?以及如何利用它?

【问题讨论】:

  • 我不会使用它,因为它只是 webkit 特定的。所以,我建议你找到它的含义,但不要使用它(不要利用它)。

标签: html dom webkit console fileapi


【解决方案1】:

在文件输入上使用webkitdirectory 属性时填充:

<input type="file" webkitdirectory>

它仅适用于 Chrome。这允许用户选择文件夹而不是文件,并且递归读取每个文件。 webkitRelativePath 包含文件在层次结构中的相对路径。

有一个演示here

【讨论】:

猜你喜欢
  • 2023-03-22
  • 2019-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-01
  • 2020-11-01
  • 1970-01-01
相关资源
最近更新 更多