Exercise 14.1
This commit is contained in:
@@ -0,0 +1,39 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Complete JavaScript Course</title>
|
||||||
|
<style>
|
||||||
|
.thumb {
|
||||||
|
max-height: 100px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<input type="file" multiple accept="image/*" />
|
||||||
|
<div class="output"></div>
|
||||||
|
<script>
|
||||||
|
const message = document.getElementById("message");
|
||||||
|
const output = document.querySelector(".output");
|
||||||
|
const myInput = document.querySelector("input");
|
||||||
|
myInput.addEventListener("change", uploadAndReadFile);
|
||||||
|
function uploadAndReadFile(e) {
|
||||||
|
const files = e.target.files;
|
||||||
|
for (let i = 0; i < files.length; i++) {
|
||||||
|
const file = files[i];
|
||||||
|
const img = document.createElement("img");
|
||||||
|
img.classList.add("thumb");
|
||||||
|
img.file = file;
|
||||||
|
output.appendChild(img);
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = (function (myImg) {
|
||||||
|
return function (e) {
|
||||||
|
myImg.src = e.target.result;
|
||||||
|
};
|
||||||
|
})(img);
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user