只读
DataTransferItem.type
property returns the type (format) of the
DataTransferItem
object representing the drag data item. The
type
is a Unicode string generally given by a MIME type, although a MIME type is not required.
Some example types are:
text/plain
and
text/html
.
dataItem.type;
A
DOMString
representing the drag data item's type.
This example shows the use of the
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 实时标准
The definition of 'type' in that specification. |
实时标准 | 初始版本 |
|
HTML 5.1
The definition of 'type' in that specification. |
推荐 | Snapshot of the HTML WHATWG document |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
type
|
Chrome 11 | Edge 12 | Firefox 50 | IE No | Opera 12 | Safari 5.1 | WebView Android 4 | Chrome Android 18 | Firefox Android 50 | Opera Android No | Safari iOS 5 | Samsung Internet Android 1.0 |
完整支持
不支持
DataTransferItem
kind
type