DragEvent.dataTransfer

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

DataEvent.dataTransfer 屬性保留了拖曳操作中的資料(指向一個 DataTransfer 物件)。

此屬性為 Read only

語法

var data = dragEvent.dataTransfer;

回傳值

data

一個保存 DragEvent 當中資料的 DataTransfer 物件。

範例

This example illustrates accessing the drag and drop data within the dragend event handler.

js
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
HTML Standard
# dom-dragevent-datatransfer-dev

瀏覽器相容性

BCD tables only load in the browser