aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/datatransferitem/kind
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/datatransferitem/kind
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/datatransferitem/kind')
-rw-r--r--files/zh-cn/web/api/datatransferitem/kind/index.html96
1 files changed, 96 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/datatransferitem/kind/index.html b/files/zh-cn/web/api/datatransferitem/kind/index.html
new file mode 100644
index 0000000000..e475661971
--- /dev/null
+++ b/files/zh-cn/web/api/datatransferitem/kind/index.html
@@ -0,0 +1,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 &lt; data.length; i += 1) {
+ if ((data[i].kind == 'string') &amp;&amp;
+ (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') &amp;&amp;
+ (data[i].type.match('^text/html'))) {
+ // Drag data item is HTML
+ console.log("... Drop: HTML");
+ } else if ((data[i].kind == 'file') &amp;&amp;
+ (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>