当前位置:网站首页>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);
});边栏推荐
猜你喜欢

今天公司碰到一个阿里p8,算是真正见识到了基础的天花板
HTTP cache browser cache that rabbits can understand

【HCIA安全】用户认证
![[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

测试用例千万不能随便,记录由一个测试用例异常引起的思考

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

In addition to "adding machines", in fact, your micro service can be optimized like this

Pointpillars: fast encoders for object detection from point clouds reading notes

About: get the domain controller of the current client login

Live broadcast appointment award | senior consultant xuyanfei: how does efficiency measurement help efficient and sophisticated outsourcing management
随机推荐
Relevant contents about wireless communication
What are the characteristics of low code tools? The two development tracks of low code that can be seen by discerning people!
Object.getOwnPropertyNames() VS Object.keys()
Practice of microservice in solving Library Download business problems
The hardest lesson we learned from the crypto Market
滤波及失真
CONDA reports an error: json.decoder.jsondecodeerror:
Redis interview questions
Multivariable time series prediction using LSTM -- problem summary
Niuke brush questions - MySQL series
golang版本管理gvm
一种用于实体关系抽取的统一标签空间
Retrieve the parameters in this method in idea for our use -- 1. Class diagram. 2. Double click shift
缩放文本以适合元素内部
拖放表格行
[HCIA security] bidirectional nat
idea中设置核心配置文件的模板
Is it reliable, reliable and safe to open an account with a low commission for funds in Galaxy Securities
[must read new] Keya valuation analysis of University of technology, heating energy-saving products
Svn uses fragmented ideas