非标
此特征是非标准的,且不在标准轨道中。不要在面向 Web 的生产站点中使用它:它不适用于每个用户。实现之间可能存在大的不兼容性,且行为将来可能改变。
HTMLInputElement.webkitdirectory
is a property that reflects the
webkitdirectory
HTML attribute and indicates that the
<input>
element should let the user select directories instead of files. When a directory is selected, the directory and its entire hierarchy of contents are included in the set of selected items. The selected file system entries can be obtained using the
webkitEntries
特性。
HTMLInputElement.webkitdirectory = boolValue
A Boolean;
true
若
<input>
element should allow picking only directories or
false
if only files should be selectable.
After the user makes a selection, each
File
object in
文件
有它自己的
File.webkitRelativePath
property set to the relative path within the selected directory at which the file is located. For example, consider this file system:
If the user chooses
PhotoAlbums
, then the list reported by files will contain
File
objects for every file listed above—but not the directories. The entry for
PIC2343.jpg
will have a
webkitRelativePath
of
PhotoAlbums/Birthdays/Don's 40th birthday/PIC2343.jpg
. This makes it possible to know the hierarchy even though the
FileList
is flat.
注意:
行为在
webkitRelativePath
is different in
Chromium < 72
。见
this bug
进一步了解细节。
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.
<input type="file" id="filepicker" name="fileList" webkitdirectory multiple /> <ul id="listing"></ul>
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 'webkitdirectory' in that specification. |
草案 | 最初的规范。 |
此 API 没有正式的 W3C 或 WHATWG (Web 超文本应用程序技术工作组) 规范。
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
webkitdirectory
非标
|
Chrome 13 | Edge 13 | Firefox 50 | IE No | Opera No | Safari 11.1 | WebView Android Yes | Chrome Android Yes | Firefox Android 50 | Opera Android No | Safari iOS 11.3 | Samsung Internet Android Yes |
完整支持
不支持
非标。预期跨浏览器支持较差。
HTMLInputElement
labels
multiple
webkitdirectory
webkitEntries
BeforeUnloadEvent
DOMStringMap
ErrorEvent
GlobalEventHandlers
HTMLAnchorElement
HTMLAreaElement
HTMLAudioElement
HTMLBRElement
HTMLBaseElement
HTMLBaseFontElement
HTMLBodyElement
HTMLButtonElement
HTMLCanvasElement
HTMLContentElement
HTMLDListElement
HTMLDataElement
HTMLDataListElement
HTMLDialogElement
HTMLDivElement
HTMLDocument
HTMLElement
HTMLEmbedElement
HTMLFieldSetElement
HTMLFormControlsCollection
HTMLFormElement
HTMLFrameSetElement
HTMLHRElement
HTMLHeadElement
HTMLHeadingElement
HTMLHtmlElement
HTMLIFrameElement
HTMLImageElement
HTMLIsIndexElement
HTMLKeygenElement
HTMLLIElement
HTMLLabelElement
HTMLLegendElement
HTMLLinkElement
HTMLMapElement
HTMLMediaElement
HTMLMetaElement
HTMLMeterElement
HTMLModElement
HTMLOListElement
HTMLObjectElement
HTMLOptGroupElement
HTMLOptionElement
HTMLOptionsCollection
HTMLOutputElement
HTMLParagraphElement
HTMLParamElement
HTMLPictureElement
HTMLPreElement
HTMLProgressElement
HTMLQuoteElement
HTMLScriptElement
HTMLSelectElement
HTMLShadowElement
HTMLSourceElement
HTMLSpanElement
HTMLStyleElement
HTMLTableCaptionElement
HTMLTableCellElement
HTMLTableColElement
HTMLTableDataCellElement
HTMLTableElement
HTMLTableHeaderCellElement
HTMLTableRowElement
HTMLTableSectionElement
HTMLTemplateElement
HTMLTextAreaElement
HTMLTimeElement
HTMLTitleElement
HTMLTrackElement
HTMLUListElement
HTMLUnknownElement
HTMLVideoElement
HashChangeEvent
历史
ImageData
定位
MessageChannel
MessageEvent
MessagePort
Navigator
NavigatorGeolocation
NavigatorID
NavigatorLanguage
NavigatorOnLine
NavigatorPlugins
PageTransitionEvent
Plugin
PluginArray
PopStateEvent
PortCollection
PromiseRejectionEvent
RadioNodeList
Transferable
ValidityState
Window
WindowBase64
WindowEventHandlers
WindowTimers