当前位置:网站首页>Preview image before uploading
Preview image before uploading
2022-07-26 21:26:00 【Ziwei front end】
We input and img Element preparation tag for previewing the selected file .
<input type="file" id="fileInput" />
<img id="preview" /> Both of these elements can be passed through the following getElementById() Method to get :
const fileEle = document.getElementById('fileInput');
const previewEle = document.getElementById('preview');1. Use URL.createObjectURL() Method
fileEle.addEventListener('change', function (e) {
// Get the selected file
const file = e.target.files[0];
// Create a new URL that references to the file
const url = URL.createObjectURL(file);
// Set the source for preview element
previewEle.src = url;
});2. Use FileReader Of readAsDataURL() Method
fileEle.addEventListener('change', function (e) {
// Get the selected file
const file = e.target.files[0];
const reader = new FileReader();
reader.addEventListener('load', function () {
// Set the source for preview element
previewEle.src = reader.result;
});
reader.readAsDataURL(file);
});边栏推荐
- Summary of common interview questions of operating system, including answers
- How to configure the legendary SF lander to automatically read the list without a network
- Test cases should never be used casually, recording the thinking caused by the exception of a test case
- 【HarmonyOS议题资料下载】HDD杭州站·线下沙龙专注应用创新 展现鸿蒙生态魅力
- Custom annotation (I)
- [HCIA security] user authentication
- [MySQL series] - how much do you know about the index
- LeetCode 练习——剑指 Offer II 005. 单词长度的最大乘积
- Mobile phone \ landline call forwarding setting method
- In addition to "adding machines", in fact, your micro service can be optimized like this
猜你喜欢

2022-7-26 第七组 抽象和接口

QT Foundation Day 1 (1) QT, GUI (graphical user interface) development

Devops has been practiced for many years. What is the most painful thing?
![[virtual machine data recovery] data recovery of XenServer virtual machine unavailable due to unexpected power failure](/img/c4/88f8927df02513eea4caffc4215850.png)
[virtual machine data recovery] data recovery of XenServer virtual machine unavailable due to unexpected power failure

GOM and GEE lander list file encryption tutorial

Detailed illustration of B-tree and its implementation in C language

一种用于实体关系抽取的统一标签空间

Error in render: “TypeError: data.slice is not a function“

今天公司碰到一个阿里p8,算是真正见识到了基础的天花板
![[MySQL series] - how much do you know about the index](/img/d7/5045a846580be106e2bf16d7b30581.png)
[MySQL series] - how much do you know about the index
随机推荐
Daily practice ----- there is a group of students' grades. Arrange them in descending order. To add a student's grade, insert it into the grade sequence and keep the descending order
制作一个可调整大小的元素
Why does it system need observability?
基于Hough变换的直线检测(Matlab)
Today, the company came across an Alibaba P8, which was really seen as the ceiling of the foundation
Is it reliable, reliable and safe to open an account with a low commission for funds in Galaxy Securities
Arm TZ hardware support
【MySQL系列】-索引知多少
QT Foundation Day 1 (1) QT, GUI (graphical user interface) development
Relevant contents about wireless communication
Ros2 method of obtaining current system time
word-break: break-all VS word-wrap: break-word
Object.getOwnPropertyNames() VS Object.keys()
GOM and GEE lander list file encryption tutorial
一种用于实体关系抽取的统一标签空间
:active vs :focus
Error in render: “TypeError: data.slice is not a function“
idea中debug时如何进入指定的用户方法体中?
Modify excel default code
立即报名:7 月 29 日推荐系统峰会 2022