语言编程:HTML 5 拖放图片

皇族网 482 0


<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
#div1 {width:400px; height:300px;padding:10px;border:1px solid #aaaaaa;}
</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>请把下面图片拖放到矩形中:</p>

<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<br />
<img id="drag1" src="https://huangzuw.com/zb_users/upload/2017/12/20171228204651151446521171382.png" draggable="true" ondragstart="drag(event)" />

</body>
</html>


标签: 语言编程 网络教程

发表评论 (已有0条评论)

还木有评论哦,快来抢沙发吧~