拖拽的事件有很多,这个懂的都懂不懂的就…
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>js拖拽文件</title>
<meta name="keywords" content="">
<meta name="description" content="">
</head>
<body>
<div id="box" style="height: 520px;width: 550px;border: 1px solid red;text-align: center;line-height: 550px;">把文件拖到此处</div>
<script>
var box=document.getElementById('box');
box.ondragover=function (e){
e.stopPropagation();
e.preventDefault();
//阻止默认事件防止浏览器打开文件方式
}
box.ondrop=function (e){
e.stopPropagation();
e.preventDefault();
console.log(e);
}
</script>
</body>
</html>
效果图
成功获取到图片数据