我在 html 中有一個這樣的檔案輸入
<input type='file' id='textin'></input>
如何獲取上傳的 .txt 檔案的內容?
uj5u.com熱心網友回復:
您可以通過FileReader執行此操作。
function previewFile() {
const content = document.querySelector('.content');
const [file] = document.querySelector('input[type=file]').files;
const reader = new FileReader();
reader.addEventListener("load", () => {
// this will then display a text file
content.innerText = reader.result;
}, false);
if (file) {
reader.readAsText(file);
}
}
<input type="file" onchange="previewFile()" id="textin"><br>
<p class="content"></p>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/371100.html
標籤:javascript html 查询
