事件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#div1,
#div3 {
float: left;
width: 150px;
height: 80px;
border-style: dashed;
text-align: center;
margin-left: 90px
}
#div2 {
margin: auto auto;
margin-top: 15px;
width: 120px;
height: 50px;
line-height: 50px;
background-color: skyblue;
}
#div3 {
float: left;
}
</style>
</head>
<body>
<!-- 来回拖动文字 -->
<div id="div1" ondragover="allDrop(event)" ondrop="drop(event)">
<div id="div2" draggable="true" ondragstart="drag(event)">runmez.dkiodi</div>
</div>
<div id="div3" ondragover="allDrop(event)" ondrop="drop(event)">
</div>
<script>
function allDrop(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>