DataTransferItem.type

这篇翻译不完整。请帮忙从英语翻译这篇文章

只读属性DataTransferItem.type 返回代表拖动数据项的 DataTransferItem 对象的类型(格式)。  type 是一个Unicode字符串,通常由MIME给出,不过不需要MIME类型。

举例一些类型: text/plain 和 text/html.

语法

dataItem.type;

返回值

一个代表拖动数据项类型的 DOMString

示例

这个例子演示了type 属性的用法。

function drop_handler(ev) {
 console.log("Drop");
 ev.preventDefault();
 var data = ev.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 == 'string') && 
              (data[i].type.match('^text/uri-list'))) {
     // Drag data item is URI
     console.log("... Drop: URI");
   } 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 Living Standard
type
Living Standard Initial version
HTML 5.1
type
Recommendation Snapshot of the HTML WHATWG document

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
typeChrome 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

另见

文档标签和贡献者

此页面的贡献者: qiudongwei
最后编辑者: qiudongwei,