44 lines
1.0 KiB
HTML
44 lines
1.0 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>文件上传demo</title>
|
|
</head>
|
|
<body>
|
|
<h1>
|
|
单文件上传
|
|
</h1>
|
|
<form>
|
|
<label for="single">上传文件</label>
|
|
<input type="file" id="sigle">
|
|
<button id="senBtn">上传</button>
|
|
</form>
|
|
<div id="fileResult">
|
|
</div>
|
|
<script>
|
|
let sigle = document.getElementById('sigle')
|
|
|
|
|
|
senBtn.addEventListener('click', ()=>{
|
|
// if(!sigle.files.length) {
|
|
// alert("请先选择文件")
|
|
// return
|
|
// }
|
|
// let formData = new FormData()
|
|
// // formData.append('touxiang', sigle.files[0])
|
|
// formData.append('name', '小明')
|
|
// fetch("/test/upload", {
|
|
// method: 'POST',
|
|
// body: formData
|
|
// }).then(res=>res.json()).then(data=>{
|
|
// fileResult.innerHTML = data.msg
|
|
// })
|
|
let formData = new FormData()
|
|
formData.append('name','下令')
|
|
formData.append('age','测试')
|
|
]
|
|
})
|
|
</script>
|
|
</body>
|
|
</html> |