--- title: DragEvent.dataTransfer slug: Web/API/DragEvent/dataTransfer translation_of: Web/API/DragEvent/dataTransfer ---
{{APIRef("HTML Drag and Drop API")}}
 

DataEvent.dataTransfer 属性保存着拖拽操作中的数据(作为一个DataTransfer对象)

This property is {{readonlyInline}}.

语法

var data = dragEvent.dataTransfer;

返回值

data
{{domxref("DataTransfer")}} 对象包含着 {{domxref("DragEvent","drag event's data")}}.

示例

这个例子展示了在{{event("dragend")}} 事件处理程序中获取拖拽中数据的方式。

function process_data(d) {
   // Process the data ...
}

dragTarget.addEventListener("dragend", function(ev) {
   // Call the drag and drop data processor
   if (ev.dataTransfer != null) process_data(ev.dataTransfer);
 }, false);

规范

Specification Status Comment
{{SpecName("HTML WHATWG", "interaction.html#dom-dragevent-datatransfer", "DragEvent.dataTransfer")}} {{Spec2("HTML WHATWG")}}  
{{SpecName("HTML5.1", "editing.html#dom-dragevent-datatransfer", "DragEvent.dataTransfer")}} {{Spec2("HTML5.1")}} Initial definition

浏览器兼容性

{{CompatibilityTable}}

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 4 {{CompatVersionUnknown}} {{CompatGeckoDesktop("1.9.1")}} 10 12 3.1
Feature Android Android Webview Chrome for Android Edge Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatNo}} {{CompatNo}} {{CompatNo}} {{CompatVersionUnknown}} {{CompatNo}} {{CompatNo}} {{CompatIE("10")}} {{CompatNo}} {{CompatNo}}