<div style
="background-color: red; width: 100%;height: 300px;" id
="bb1">
<button
>
file
</button
>
<div
>
拖拽文件
</div
>
</div
>
const fs
= require('fs');
const dragWrapper
= document
.getElementById("bb1");
dragWrapper
.addEventListener("drop", (e
) => {
e
.preventDefault();
const files
= e
.dataTransfer
.files
;
if (files
&& files
.length
> 0) {
const path
= files
[0].path
console
.log("path", path
);
const content
= fs
.readFileSync(path
)
console
.log("content", content
.toString());
}
})
dragWrapper
.addEventListener("dragover", (e
) => {
e
.preventDefault()
})
转载请注明原文地址:https://blackberry.8miu.com/read-42701.html