Baseline Widely available
FileList
ì íì ê°ì²´ë HTML <input>
ììì files
ìì±ì´ë Drag and Drop APIì DataTransfer
ìì ê°ì ¸ì¬ ì ìì¼ë©°, <input type="file">
ììë¡ ì ííê±°ë ì¹ ì½í
ì¸ ìì ëì´ë¤ ëì íì¼ ëª©ë¡ì ëí ì ê·¼ì ì ê³µí©ëë¤.
모ë <input>
ìì ë
¸ëìë FileList
를 ë°ííë files
í¹ì±ì´ ìì´ì íì¼ì 목ë¡ì ì ê·¼í ì ììµëë¤. ì를 ë¤ì´, ë¤ìê³¼ ê°ì HTML ì½ë를 ê°ì íë©´,
<input id="fileItem" type="file" />
ìë ì½ëë¡ ë
¸ëì íì¼ ë¦¬ì¤í¸ìì 첫 ë²ì§¸ í목ì File
ê°ì²´ë¡ ê°ì ¸ì¬ ì ììµëë¤.
const file = document.getElementById("fileItem").files[0];
ìì±
length
ì½ê¸° ì ì©
리ì¤í¸ê° í¬í¨í íì¼ì ì를 ëíë´ë ì½ê¸° ì ì© ê°ì ëë¤.
item()
ì½ê¸° ì ì©
íì¼ ë¦¬ì¤í¸ìì ì§ì í ì¸ë±ì¤ì ìì¹í íì¼ì ëíë´ë File
ê°ì²´ë¥¼ ë°íí©ëë¤.
ì´ ìì ììë ì¬ì©ìê° ì íí íì¼ë¤ì ì´ë¦ì 기ë¡í©ëë¤.
HTML<!--'multiple'ì ì§ì í´ì ì¬ë¬ íì¼ì ì íì íì©-->
<input id="myfiles" multiple type="file" />
<div class="output"></div>
CSS
.output {
overflow: scroll;
margin: 1rem 0;
height: 200px;
}
JavaScript
const output = document.querySelector(".output");
const myFiles = document.querySelector("#myfiles");
function logFilenames() {
const fileInput = document.querySelector("#myfiles");
const files = fileInput.files;
const fileListLength = files.length;
for (let i = 0; i < fileListLength; i++) {
output.innerText = `${output.innerText}\n${files.item(i).name}`;
}
}
myFiles.addEventListener("change", logFilenames);
ê²°ê³¼ ëª
ì¸ ë¸ë¼ì°ì í¸íì± ê°ì´ 보기
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4