GlobalEventHandlers.ondrop - Web API 接口参考 编辑
drop 事件的全局处理函数
语法
var dropHandler = targetElement.ondrop;
返回值
dropHandler
- 目标元素的 drop 事件处理函数。
Example
下面这个示例演示了 ondrop 属性的用法来指定 drop 事件的处理函数。
<!DOCTYPE html>
<html lang=en>
<title>Examples of using the ondrag Global Event Attribute</title>
<meta content="width=device-width">
<style>
div {
margin: 0em;
padding: 2em;
}
#source {
color: blue;
border: 1px solid black;
}
#target {
border: 1px solid black;
}
</style>
</head>
<script>
function drag_handler(ev) {
console.log("Drag");
}
function dragstart_handler(ev) {
console.log("dragStart");
ev.dataTransfer.setData("text", ev.target.id);
}
function drop_handler(ev) {
console.log("Drop");
ev.currentTarget.style.background = "lightyellow";
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
function dragover_handler(ev) {
console.log("dragOver");
ev.preventDefault();
}
</script>
<body>
<h1>Examples of <code>ondrag</code>, <code>ondrop</code>, <code>ondragstart</code>, <code>ondragover</code></h1>
<div class="source">
<p id="source" ondrag="drag_handler(event);" ondragstart="dragstart_handler(event);" draggable="true">
Select this element, drag it to the Drop Zone and then release the selection to move the element.</p>
</div>
<div id="target" ondrop="drop_handler(event);" ondragover="dragover_handler(event);">Drop Zone</div>
</body>
</html>
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard ondrop | Living Standard | |
HTML 5.1 ondrop | Recommendation | Initial definition |
Browser compatibility
We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 4 | 3.5 (1.9.1) | 10 | 12 | 3.1 |
Feature | Android | Android Webview | Chrome for Android | Firefox Mobile (Gecko) | Firefox OS | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|---|
Basic support | 未实现 | 未实现 | 未实现 | 未实现 | 未实现 | 10 | 未实现 | 未实现 |
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论