예제
<!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>
</head>
<body>
<div class="image-upload">
<label for="file-input">
<img src="./upload.jpg" />
</label>
<input id="file-input" type="file" multiple />
</div>
<div id="preview-container"></div>
<script>
document.querySelector('#file-input').addEventListener('change', e => {
const preview = document.querySelector('#preview-container');
preview.innerHTML = '';
const file = e.currentTarget.files;
console.log(file);
Array.from(file).forEach((v, i) => {
console.log(v);
const img = URL.createObjectURL(v);
const div = document.createElement('div');
div.classList.add('previews');
div.style.backgroundImage = 'url(' + img + ')';
preview.appendChild(div);
});
});
</script>
</body>
</html>