<!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>
* {
margin: 0;
padding: 0;
}
div {
width: 600px;
height: 600px;
background-color: #ccc;
}
</style>
</head>
<body>
<div id="dv">
</div>
<script>
function f1(fr) {
fr.addEventListener("load", function () {
var img = document.createElement("img");
img.src = fr.result;
// console.log(fr.result);
dv.appendChild(img);
})
}
var dv = document.getElementById("dv");
dv.ondragover = function (e) {
e.preventDefault();
}
dv.ondrop = function (e) {
e.preventDefault();
console.log(e.dataTransfer.files.length);
for (let i = 0; i < e.dataTransfer.files.length; i++) {
console.log(e.dataTransfer.files[i]);
var fr = new FileReader();
fr.readAsDataURL(e.dataTransfer.files[i]);
f1(fr);
}
}
</script>
</body>
</html>
2021-08-12
最新推荐文章于 2024-11-10 15:10:09 发布