<!DOCTYPE HTML>
<html>
<head>
<title></title>
<meta charset="utf-8"/>
<style>
#div1{width:200px; height:200px;border:solid 1px gray;}
#div2{width:200px; height:200px;border:solid 1px gray;}
img{border:solid 1px red;}
</style>
</head>
<div id="div1" ondragover="allowDrag(event)" ondrop="dropImg(event)"></div>
<div id="div2" ondragover="allowDrag(event)" ondrop="dropImg(event)">
<img id="img1" src="22.gif" draggable="true" ondragstart="dragImg(event)"/>
</div>
<script>
function dragImg(ev){
ev.dataTransfer.setData("heh",ev.target.id);
}
function allowDrag(ev){
ev.preventDefault();
}
function dropImg(ev){
ev.preventDefault();
var data = ev.dataTransfer.getData("heh");
//console.log(document.getElementById(data));
ev.target.appendChild(document.getElementById(data));
}
</script>
<body>
</body>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。