终端操作:
koa2 -e upload
cd upload
npm install
目录:
step1: views/index.ejs
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link rel="stylesheet" href="/stylesheets/style.css" />
</head>
<body>
<input type="file" id="file1" />
<button id="btn">上传文件</button>
</body>
<script>
// 方法存入”$""
let $ = document.querySelector.bind(document);
let file1 = $("#file1");
let btn = $("#btn");
file1.onchange = function (e) {
// 拿到现在文件的列表
// console.log(e);
// console.log(file1.files);
let fileObj = file1.files[0];
console.log(fileObj);
};
</script>
</html>