aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/window/ondragdrop/index.html
blob: 4a99f9da309fee1e6242ce9207d1fc4b4f0538dc (plain)
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
---
title: Window.ondragdrop
slug: Web/API/Window/ondragdrop
translation_of: Web/API/Window/ondragdrop
---
<div class="warning">
<p>在Firefox 50中已删除,并且从未在任何其他浏览器中实行。 请改用现代标准的<a href="/en-US/docs/Web/API/HTML_Drag_and_Drop_API">HTML5拖放</a>功能。</p>
</div>

<h2 id="Summary" name="Summary">摘要</h2>

<p>一个事件处理程序,用于将拖放事件发送到窗口。</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>

<pre class="eval notranslate"><s>window.ondragdrop = funcRef;</s>
window.addEventListener("dragdrop", funcRef, useCapturing);
</pre>

<dl>
 <dt>funcRef </dt>
 <dd>要注册的事件处理函数。</dd>
</dl>

<p><a href="/zh-CN/docs/Web/API/Window/en/Gecko">Gecko</a>({{ Bug(112288) }})中未实现<code>window.ondragdrop</code>属性和<code>ondragdrop</code>属性,您必须使用<code>addEventListener</code>。 有关详细信息,请参见<a href="/zh-CN/docs/Web/API/Window/en/DOM/element.addEventListener">addEventListener</a></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>

<h3 id="Fire_an_alert_on_dragdrop" name="Fire_an_alert_on_dragdrop">在拖放时触发alert</h3>

<p>在此示例中,事件侦听器被添加到窗口(事件目标)。 如果从外部源将选项卡,链接,标记的文本或文件拖放到此窗口上,则会触发警报。 注意<code>event.stopPropagation()</code>; 阻止浏览器加载放置的标签,链接或文件。</p>

<pre class="notranslate">&lt;html&gt;
&lt;head&gt;&lt;title&gt;dragdroptest&lt;/title&gt;

&lt;script type="text/javascript"&gt;

window.addEventListener("dragdrop", testfunc, false);

function testfunc(event) {
    alert("dragdrop!");
    event.stopPropagation();
}
&lt;/script&gt;

&lt;/head&gt;
&lt;body&gt;
I am bodytext
&lt;/body&gt;
&lt;/html&gt;
</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>

<p>不属于规范部分。<span class="external"> </span></p>