<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>文件上传</title>
</head>
<body>
<div id="app">
<input type="file" name="" id="input_img" />
<div id="show_img" style="width: 400px;height: 400px;display: flex;align-items: center;justify-content: center;overflow: hidden;"></div>
</div>
<script>
var getUserPhoto = document.getElementById("input_img");
getUserPhoto.onchange = function () {
var file = this.files;
console.log(file);
var reader = new FileReader();
reader.readAsDataURL(file[0]);
reader.onload = function () {
var image = document.createElement("img");
image.width = "400";
image.src = reader.result;
var showPicture = document.getElementById("show_img");
showPicture.append(image);
};
};
</script>
</body>
</html>
本站资源均来自互联网,仅供研究学习,禁止违法使用和商用,产生法律纠纷本站概不负责!如果侵犯了您的权益请与我们联系!
转载请注明出处: 免费源码网-免费的源码资源网站 » html 使用input file上传图片并显示
发表评论 取消回复