file upload start
This commit is contained in:
parent
b0c2dba1d6
commit
7693c7c931
5 changed files with 98 additions and 3 deletions
26
src/public/index.js
Normal file
26
src/public/index.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// Select the file input element
|
||||
const fileInput = document.querySelector('input[type="file"]');
|
||||
|
||||
// Add a 'change' event listener to the file input element
|
||||
fileInput.addEventListener("change", (e) => {
|
||||
console.log(e.target.files);
|
||||
// Get the selected files from the event target
|
||||
const files = e.target.files;
|
||||
|
||||
// Select the file-list table
|
||||
const fileList = document.querySelector("#file-list");
|
||||
|
||||
// Loop through the selected files
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
// Create a new table row for each file
|
||||
const row = document.createElement("tr");
|
||||
row.innerHTML = `
|
||||
<td>${files[i].name}</td>
|
||||
<td>${(files[i].size / 1024 / 1024).toFixed(2)} MB</td>
|
||||
<td><button class="secondary">x</button></td>
|
||||
`;
|
||||
|
||||
// Append the row to the file-list table
|
||||
fileList.appendChild(row);
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue