我对 Html5 完全陌生,我的借口可能是在代码上遗漏了一些实质性或严重错误。我无法弄清楚为什么这段代码不起作用。错误的解释将非常受欢迎。
<head>
<title>Drag and Drop</title>
<meta charset-"UTF-8">
<style type="text/css">
#box_1, #box_2{
position: relative;
width: 250px;
height: 250px;
margin: 10px;
border: 1px solid black;
float: left;
}
</style>
<script type="text/javascript">
function allowDrop(ev){
ev.preventDefault();
}
function drag(ev){
ev.dataTransfer.setData("content", ev.target.id);
}
function drop(ev){
ev.preventDefault();
var image= ev.dataTransfer.getData("content");
ev.target.appendChild(document.getElementById(image));
}
</script>
</head>
<body>
<div id-"box_1" ondrop-"drop(event)" ondragover-"allowDrop(event)">
<img src="C:\Users\Public\Pictures\Sample Pictures\Koala.jpg" alt="logo" id="logo" draggable="true" ondragstart-"drag(event)"
width= 100px;
height=100px;/>
</div>
<div id-"box_2" ondrop="drop(event)" ondragover-"allowDrop(event)">
</div>
</body>
</html>