DataTransferItem.kind

DataTransferItem.kind 是一个只读属性,它返回一个 DataTransferItem 用来表示拖拽项(drag data item)的类型: 一些文本或者一些文件。

语法

var itemKind = DataTransferItem.kind;

返回值

 DOMString 用来表示拖拽项(drag data item)的类型. 它的值必须是以下值中的一个:

'file'
拖拽项是一个文件。
'string'
拖拽项是一个普通的 Unicode 字符。

例子

下面这个例子是 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 ");
   }
 }
}

规范

Specification Status Comment
HTML Living Standard
kind
Living Standard Initial version
HTML 5.1
kind
Recommendation W3C snapshot of the WHATWG document.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
kindChrome Full support 4Edge Full support 12Firefox Full support 50IE No support NoOpera Full support 12Safari No support NoWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 50Opera Android No support NoSafari iOS No support NoSamsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

查看更多