DragEvent.dataTransfer

 

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

This property is 只读 .

语法

var data = dragEvent.dataTransfer;

返回值

data
DataTransfer 对象包含着 drag event's data.

示例

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

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
HTML Living Standard
DragEvent.dataTransfer
Living Standard  
HTML 5.1
DragEvent.dataTransfer
Recommendation Initial definition

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help! (en-US)

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 4 (Yes) 3.5 (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 未实现 未实现 未实现 (Yes) 未实现 未实现 10 未实现 未实现