-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrag.html
More file actions
42 lines (37 loc) · 812 Bytes
/
drag.html
File metadata and controls
42 lines (37 loc) · 812 Bytes
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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="name" content="content">
<style type="text/css">
#div1 {width:488px;height:70px;padding:10px;border:1px solid #aaaaaa;}
#drag1{
width:200px;
height:50px;
background-color:red;
}
</style>
<script type="text/javascript">
function allowDrop(ev)
{
ev.preventDefault();
}
function drag(ev)
{
ev.dataTransfer.setData("Text",ev.target.id);
}
function drop(ev)
{
ev.preventDefault();
var data=ev.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(data));
}
</script>
</head>
<body>
<p>请把 W3School 的图片拖放到矩形中:</p>
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<br />
<div id="drag1" src="/i/w3school_banner.gif" draggable="true" ondragstart="drag(event)" />
</body>
</html>