Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/426.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 删除多个输入文件的选定文件名_Javascript_Jquery_Html_Arraylist_File Upload - Fatal编程技术网

Javascript 删除多个输入文件的选定文件名

Javascript 删除多个输入文件的选定文件名,javascript,jquery,html,arraylist,file-upload,Javascript,Jquery,Html,Arraylist,File Upload,目前我的代码与此处的代码相同: 如何将文件列表转换为数组,并在每个文件名旁边添加一个删除链接,然后在上载之前将其删除 谢谢。 <input type="file" id="file" multiple> <ul id="list"></ul> let file=document.getElementById("file"); let list=document.getElementById("list"); let fileList=

目前我的代码与此处的代码相同:

如何将文件列表转换为数组,并在每个文件名旁边添加一个删除链接,然后在上载之前将其删除

谢谢。


    <input type="file" id="file" multiple>
    <ul id="list"></ul>  

let file=document.getElementById("file");
let list=document.getElementById("list");


let fileList=[];

file.addEventListener("change",(e)=>{
    Array.prototype.forEach.call(e.target.files,(file)=>{
        fileList.push(file);
    });
    updateList();
});

function updateList(){
    list.innerHTML="";
    fileList.forEach((file)=>{
        let li=document.createElement("li");
        li.innerHTML="<span>"+file.name+"</span><a href='javascript:void(0)' class='remove'>remove</a>";
        list.appendChild(li);
    });
}


list.addEventListener("click",(e)=>{
    let target=e.target;
    if(target.className=="remove"){
        let parent=target.parentNode;
        let fileName=parent.children[0].innerText;
        refreshList(fileName);
    }
});

function refreshList(fileName){
    fileList=fileList.filter((file)=>{
    return  file.name.indexOf(fileName)==-1;
  });
    console.log(fileList);
    updateList();
}
    让file=document.getElementById(“文件”); let list=document.getElementById(“list”); 让fileList=[]; addEventListener(“更改”,(e)=>{ Array.prototype.forEach.call(e.target.files,(file)=>{ fileList.push(文件); }); updateList(); }); 函数updateList(){ list.innerHTML=“”; fileList.forEach((文件)=>{ 设li=document.createElement(“li”); li.innerHTML=“”+文件名+”; 表1.儿童(李); }); } list.addEventListener(“单击”,(e)=>{ 设target=e.target; if(target.className==“删除”){ 让parent=target.parentNode; 让fileName=parent.children[0].innerText; 刷新列表(文件名); } }); 函数刷新列表(文件名){ fileList=fileList.filter((文件)=>{ 返回file.name.indexOf(fileName)=-1; }); console.log(文件列表); updateList(); }
    我会使用递归函数来实现这一点。请参见下面的解决方案:

    函数更新列表(){
    var input=document.getElementById('file');
    //创建列表或数组
    var列表=[];
    对于(变量i=0,len=input.files.length;i
    
    
    所选文件:
    感谢您帮助Chand Ra,那么需要启动您编写的sweet remove功能的remove链接呢?如何在文件名旁边添加删除链接?