简体   繁体   中英

How to show a new file-upload button after uploading?

I want to have infinite file-upload buttons. Right after I send a file, a new button appears.

How can I do something like:

无限文件上传按钮

您可以向元素添加事件侦听器以侦听更改并设置createUploadButton函数以在事件传递时触发。

element.addEventListener('change', createUploadButton);

The exact answer to your question is bellow:

 function makeNewButton() { //create an upload button: let uploadbtn = document.createElement('input'); uploadbtn.setAttribute('type', 'file'); //append it to your document: document.body.appendChild(uploadbtn); //add an event listener that fires the function again: uploadbtn.addEventListener('change', makeNewButton); //make delete element: let deletetext = document.createElement('p'); deletetext.textContent = 'Delete'; //append it to your document: document.body.appendChild(deletetext); //Add an event listener to remove the original button and the delete link on click: deletetext.addEventListener('click', function() { uploadbtn.remove(); deletetext.remove(); }); } makeNewButton();

Full documentation to the document interface can be found here: https://developer.mozilla.org/en-US/docs/Web/API/Document

Handling the files and sending them to the server is a different mater.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM