只读 DataTransferItem.kind 特性返回 DataTransferItem 表示 drag data item kind: some text or some file.

句法

var itemKind = DataTransferItem.kind;
					

返回值

A DOMString representing the drag data item's kind. It must be one of the following values:

'file'

If the drag data item is a file.

'string'
If the kind of drag data item is a plain Unicode string .

范例

This example shows the use of the kind 特性。

function drop_handler(ev) {
 console.log("Drop");
 ev.preventDefault();
 var data = event.dataTransfer.items;
 for (var i = 0; i < data.length; i += 1) {
   if ((data[i].kind == 'string') &&
       (data[i].type.match('^text/plain'))) {
     // This item is the target node
     data[i].getAsString(function (s){
       ev.target.appendChild(document.getElementById(s));
     });
   } else if ((data[i].kind == 'string') &&
              (data[i].type.match('^text/html'))) {
     // Drag data item is HTML
     console.log("... Drop: HTML");
   } else if ((data[i].kind == 'file') &&
              (data[i].type.match('^image/'))) {
     // Drag data item is an image file
     var f = data[i].getAsFile();
     console.log("... Drop: File ");
   }
 }
}
					

规范

规范 状态 注释
HTML 实时标准
The definition of 'kind' in that specification.
实时标准 初始版本
HTML 5.1
The definition of 'kind' in that specification.
推荐 W3C snapshot of the WHATWG document.

浏览器兼容性

The compatibility table on 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
kind Chrome 11 Edge 12 Firefox 50 IE No Opera 12 Safari 5.1 WebView Android 4 Chrome Android 18 Firefox Android 50 Opera Android No Safari iOS 5 Samsung Internet Android 1.0

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: