浏览器拖动文件上传
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<script src="js/c.js" type="text/javascript" charset="utf-8"></script>
</head>
<style type="text/css">
.box {
padding:50px;
border:1px dotted #ccc;
}
</style>
<body>
<div class="box"></div>
<script>
//禁止浏览器打开图片行为
document.addEventListener("drop", function (e) { //拖离
e.preventDefault();
})
document.addEventListener("dragleave", function (e) { //拖后放
e.preventDefault();
})
document.addEventListener("dragenter", function (e) { //拖进
e.preventDefault();
});
document.addEventListener("dragover", function (e) { //拖来拖去
e.preventDefault();
});
document.getElementsByClassName('box')[0].addEventListener("drop", function (e) { //拖离
e.preventDefault();
console.log(123)
})
</script>
</body>
<script src="js/jquery.js" type="text/javascript" charset="utf-8"></script>
</html>