html>
Document#box{
width:300px;
height:180px;
border:1px solid #000;
}
#img1{
width:200px;
height:120px;
margin: 20px;
}
window.οnlοad=function(){
var box=document.getElementById('box'),
img1=document.getElementById('img1');
img1.οndragstart=drag(event);
box.οndragοver=allowdrop(event);
box.οndrοp=drop(event);
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));
}
}
当我把ondragstart ondragover ondrop事件放在HTML元素标签内时,代码正常运行,但是像上边放在