x
1
2
<html>
3
<head>
4
<meta charset="utf-8">
5
<style type="text/css">
6
#div1 {
7
width: 350px;
8
height: 70px;
9
padding: 10px;
10
border: 1px solid #aaaaaa;
11
}
12
</style>
13
<script>
14
function allowDrop(ev) {
15
ev.preventDefault();
16
}
17
18
function drag(ev) {
19
ev.dataTransfer.setData("Text", ev.target.id);
20
}
21
22
function drop(ev) {
23
ev.preventDefault();
24
var data = ev.dataTransfer.getData("Text");
25
ev.target.appendChild(document.getElementById(data));
26
}
27
</script>
28
</head>
29
<body>
30
<p>拖动蜜蜂教程的图片到矩形框中:</p>
31
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
32
<br>
33
<img id="drag1" src="/images/logo.png" draggable="true" ondragstart="drag(event)" width="180">
34
</body>
35
</html>