DataTransferItem:kind 属性
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
只读属性 DataTransferItem.kind
返回代表拖动数据项的 DataTransferItem
对象的类别——字符串或文件。
值
示例
以下示例展示了 kind
属性的用法。
js
function dropHandler(ev) {
console.log("放置");
ev.preventDefault();
const data = event.dataTransfer.items;
for (let i = 0; i < data.length; i += 1) {
if (data[i].kind === "string" && data[i].type.match("^text/plain")) {
// 该项目是目标节点
data[i].getAsString((s) => {
ev.target.appendChild(document.getElementById(s));
});
} else if (data[i].kind === "string" && data[i].type.match("^text/html")) {
// 拖动数据项是 HTML
console.log("… Drop: HTML");
} else if (data[i].kind === "file" && data[i].type.match("^image/")) {
// 拖动数据项是图像文件
const f = data[i].getAsFile();
console.log("……放置:文件");
}
}
}
规范
Specification |
---|
HTML Standard # dom-datatransferitem-kind-dev |
浏览器兼容性
BCD tables only load in the browser