非标
此特征是非标准的,且不在标准轨道中。不要在面向 Web 的生产站点中使用它:它不适用于每个用户。实现之间可能存在大的不兼容性,且行为将来可能改变。

File.webkitRelativePath is a read-only property that contains a USVString which specifies the file's path relative to the directory selected by the user in an <input> element with its webkitdirectory attribute set.

句法

 relativePath = File.webkitRelativePath
					

A USVString containing the path of the file relative to the ancestor directory the user selected.

范例

In this example, a directory picker is presented which lets the user choose one or more directories. When the change event occurs, a list of all files contained within the selected directory hierarchies is generated and displayed.

HTML 内容

<input type="file" id="filepicker" name="fileList" webkitdirectory multiple />
<ul id="listing"></ul>
					

JavaScript 内容

document.getElementById("filepicker").addEventListener("change", function(event) {
  let output = document.getElementById("listing");
  let files = event.target.files;
  for (let i=0; i<files.length; i++) {
    let item = document.createElement("li");
    item.innerHTML = files[i].webkitRelativePath;
    output.appendChild(item);
  };
}, false);
					

结果

规范

规范 状态 注释
文件和目录条目 API
The definition of 'webkitRelativePath' in that specification.
草案 最初的规范。

此 API 没有正式的 W3C 或 WHATWG (Web 超文本应用程序技术工作组) 规范。

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
webkitRelativePath Chrome 13 Prefixed
13 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge 13 Firefox 49 IE No Opera No Safari 11.1 WebView Android Yes Chrome Android 18 Prefixed
18 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android 49 Opera Android No Safari iOS 11.3 Samsung Internet Android 1.0 Prefixed
1.0 Prefixed
Prefixed Implemented with the vendor prefix: webkit

图例

完整支持

完整支持

不支持

不支持

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

另请参阅

元数据

  • 最后修改:
  1. File
  2. 构造函数
    1. File()
  3. 特性
    1. fileName
    2. fileSize
    3. lastModified
    4. lastModifiedDate
    5. mozFullPath
    6. 名称
    7. type
    8. webkitRelativePath
  4. 方法
    1. getAsBinary()
    2. getAsDataURL()
    3. getAsText()
  5. 继承:
    1. Blob
  6. 文件 API 相关页面
    1. Blob
    2. FileList
    3. FileReader
    4. FileReaderSync

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1