aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/datatransfer/items
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/datatransfer/items
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/datatransfer/items')
-rw-r--r--files/zh-cn/web/api/datatransfer/items/index.html113
1 files changed, 113 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/datatransfer/items/index.html b/files/zh-cn/web/api/datatransfer/items/index.html
new file mode 100644
index 0000000000..27fadf40d5
--- /dev/null
+++ b/files/zh-cn/web/api/datatransfer/items/index.html
@@ -0,0 +1,113 @@
+---
+title: DataTransfer.items
+slug: Web/API/DataTransfer/items
+translation_of: Web/API/DataTransfer/items
+---
+<div>{{APIRef("HTML Drag and Drop API")}}</div>
+
+<p>{{domxref("DataTransfer")}}的<code>items</code> 属性只读,是拖动操作中 {{domxref("DataTransferItem","数据传输项")}}的{{domxref("DataTransferItemList","列表")}}。该列表包含了操作中每一项目的对应项,如果操作没有项目,则列表为空。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox"><em>itemList</em> = <em>dataTransfer</em>.items;
+</pre>
+
+<h3 id="返回值">返回值</h3>
+
+<p>一个{{domxref("DataTransferItemList")}} 对象,包含了表示拖动操作中被拖动项的{{domxref("DataTransferItem")}}对象,每一个拖动项对应一个列表项。如果拖动操作中没有数据,则列表为空。</p>
+
+<h2 id="示例">示例</h2>
+
+<p>这个例子演示了 <code>items</code> 和 {{domxref("DataTransfer.types","types")}} 属性的用法.</p>
+
+<pre class="brush: js">&lt;!DOCTYPE html&gt;
+&lt;html lang=en&gt;
+&lt;title&gt;Examples of DataTransfer.{types,items} properties&lt;/title&gt;
+&lt;meta content="width=device-width"&gt;
+&lt;style&gt;
+ div {
+ margin: 0em;
+ padding: 2em;
+ }
+ #target {
+ border: 1px solid black;
+ }
+&lt;/style&gt;
+&lt;script&gt;
+function dragstart_handler(ev) {
+ console.log("dragStart: target.id = " + ev.target.id);
+ // Add this element's id to the drag payload so the drop handler will
+ // know which element to add to its tree
+ ev.dataTransfer.setData("text/plain", ev.target.id);
+ ev.dataTransfer.effectAllowed = "move";
+}
+
+function drop_handler(ev) {
+ console.log("drop: target.id = " + ev.target.id);
+ ev.preventDefault();
+ // Get the id of the target and add the moved element to the target's DOM
+ var data = ev.dataTransfer.getData("text");
+ ev.target.appendChild(document.getElementById(data));
+ // Print each format type
+ if (ev.dataTransfer.types != null) {
+ for (var i=0; i &lt; ev.dataTransfer.types.length; i++) {
+ console.log("... types[" + i + "] = " + ev.dataTransfer.types[i]);
+ }
+ }
+ // Print each item's "kind" and "type"
+ if (ev.dataTransfer.items != null) {
+ for (var i=0; i &lt; ev.dataTransfer.items.length; i++) {
+ console.log("... items[" + i + "].kind = " + ev.dataTransfer.items[i].kind + " ; type = " + ev.dataTransfer.items[i].type);
+ }
+ }
+}
+
+function dragover_handler(ev) {
+ console.log("dragOver");
+ ev.preventDefault();
+ // Set the dropEffect to move
+ ev.dataTransfer.dropEffect = "move"
+}
+&lt;/script&gt;
+&lt;body&gt;
+&lt;h1&gt;Examples of &lt;code&gt;DataTransfer&lt;/code&gt;.{&lt;code&gt;types&lt;/code&gt;, &lt;code&gt;items&lt;/code&gt;} properties&lt;/h1&gt;
+ &lt;ul&gt;
+ &lt;li id="i1" ondragstart="dragstart_handler(event);" draggable="true"&gt;Drag Item 1 to the Drop Zone&lt;/li&gt;
+ &lt;li id="i2" ondragstart="dragstart_handler(event);" draggable="true"&gt;Drag Item 2 to the Drop Zone&lt;/li&gt;
+ &lt;/ul&gt;
+ &lt;div id="target" ondrop="drop_handler(event);" ondragover="dragover_handler(event);"&gt;Drop Zone&lt;/div&gt;
+&lt;/body&gt;
+&lt;/html&gt;
+</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">规范</th>
+ <th scope="col">状态</th>
+ <th scope="col">备注</th>
+ </tr>
+ <tr>
+ <td>{{SpecName("HTML WHATWG", "interaction.html#dom-datatransfer-items", "items")}}</td>
+ <td>{{Spec2("HTML WHATWG")}}</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>{{SpecName("HTML5.1", "editing.html#dom-datatransfer-items", "items")}}</td>
+ <td>{{Spec2("HTML5.1")}}</td>
+ <td>Initial definition</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("api.DataTransfer.items")}}</p>
+
+<h2 id="另见">另见</h2>
+
+<p>{{page("/en-US/docs/Web/API/DataTransfer", "See also")}}</p>