1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
---
title: DataTransferItem.kind
slug: Web/API/DataTransferItem/kind
tags:
- API
- DataTransferItem
- HTML DOM
- HTML Drag and Drop API
- Property
- Reference
- drag and drop
- kind
translation_of: Web/API/DataTransferItem/kind
---
<div>{{APIRef("HTML Drag and Drop API")}}</div>
<p><strong><code>DataTransferItem.kind</code></strong> 是一个只读属性,它返回一个 {{domxref("DataTransferItem")}} 用来表示拖拽项(<em>drag data item)的类型</em>: 一些文本或者一些文件。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox">var <em>itemKind</em> = <em>DataTransferItem</em>.kind;
</pre>
<h3 id="返回值">返回值</h3>
<p> {{domxref("DOMString")}} 用来表示拖拽项(<em>drag data item)的类型</em>. 它的值必须是以下值中的一个:</p>
<dl>
<dt><code>'file'</code></dt>
<dd>拖拽项是一个文件。</dd>
<dt><code>'string'</code></dt>
<dd>拖拽项是一个普通的 Unicode 字符。</dd>
</dl>
<h2 id="例子">例子</h2>
<p>下面这个例子是 <code>kind</code> 属性的用法.</p>
<pre class="brush: js">function drop_handler(ev) {
console.log("Drop");
ev.preventDefault();
var data = event.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 == 'file') &&
(data[i].type.match('^image/'))) {
// Drag data item is an image file
var f = data[i].getAsFile();
console.log("... Drop: File ");
}
}
}
</pre>
<p><font face="x-locale-heading-primary, zillaslab, Palatino, Palatino Linotype, x-locale-heading-secondary, serif"><span style="font-size: 37.33327865600586px;"><strong>规范</strong></span></font></p>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('HTML WHATWG', 'interaction.html#dom-datatransferitem-kind','kind')}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
<td>Initial version</td>
</tr>
<tr>
<td>{{SpecName('HTML5.1', 'editing.html#dom-datatransferitem-kind','kind')}}</td>
<td>{{Spec2('HTML5.1')}}</td>
<td>W3C snapshot of the WHATWG document.</td>
</tr>
</tbody>
</table>
<p><font face="x-locale-heading-primary, zillaslab, Palatino, Palatino Linotype, x-locale-heading-secondary, serif"><span style="font-size: 37.33327865600586px;"><strong>浏览器兼容性</strong></span></font></p>
<p>{{Compat("api.DataTransferItem.kind")}}</p>
<p><font face="x-locale-heading-primary, zillaslab, Palatino, Palatino Linotype, x-locale-heading-secondary, serif"><span style="font-size: 37.33327865600586px;"><strong>查看更多</strong></span></font></p>
<p>{{page("/en-US/docs/Web/API/DataTransfer", "See also")}}</p>
<p> </p>
|