HTML5--拖放

<!DOCTYPE html>
<html>
<head>
<style type="text/css">
#div1 {width:350px;height:70px;padding:10px;border:1px solid #aaaaaa;}
</style>
<script>
function allowDrop(ev){
    ev.preventDefault();
}
function drag(ev){
    //alert(ev.target.id);
    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>
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<img id="drag1" src="images/img1.png" draggable="true" ondragstart="drag(event)" width="206" height="69"/>
</body>
</html>

 

posted @ 2016-07-27 12:02  公众号java-codestack  阅读(138)  评论(0编辑  收藏  举报