-
Notifications
You must be signed in to change notification settings - Fork 0
/
domfiles.html
93 lines (73 loc) · 2.28 KB
/
domfiles.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
section{
width: 100%;
height: 100vh;
background: #efefec;
}
img{
height: 100px;
width: 100px;
}
</style>
</head>
<body>
<section>
<input type="file" name="" multiple>
</section>
<script>
let input=document.querySelector("input");
let section=document.querySelector("section")
input.addEventListener("change",e=>{
let rawfile=e.target.files[0];
let dataformat=new FileReader();//one way
dataformat.readAsDataURL(rawfile);
dataformat.addEventListener("load",e=>{
let first=dataformat.result;
console.log(first);
window.localStorage.setItem("img",first);
let img=document.createElement("img");
img.setAttribute("src",window.localStorage.getItem("img"));
section.appendChild(img)
});
});
// });
//another way
// input.addEventListener("change",e=>{
// window.localStorage.removeItem("img",img);
// window.localStorage.removeItem("img1",img1);
// window.localStorage.removeItem("img2",img2);
// let data=e.target.files[0];
// let dataformat=new FileReader();
// dataformat.readAsDataURL(data);
// dataformat.onload=function(){
// let img=dataformat.result;
// window.localStorage.setItem("img",img);
// }
// dataformat.onload=function(){
// let img1=dataformat.result;
// window.localStorage.setItem("img1",img1);
// };
// dataformat.onload=function(){
// let img2=dataformat.result;
// window.localStorage.setItem("img2",img2);
// };
// });
// let z=document.querySelector(".img-url")
// z.setAttribute("src",window.localStorage.getItem("img"));
// console.log(z);
// let z1=document.querySelector(".img-url1")
// z1.setAttribute("src",window.localStorage.getItem("img1"));
// console.log(z1);
// let z3=document.querySelector(".img-url2")
// console.log(z3);
// z3.setAttribute("src",window.localStorage.getItem("img2"));
</script>
</body>
</html>