Remove a FileList item from a multiple “input:file”

后端 未结 5 1138
生来不讨喜
生来不讨喜 2020-12-01 16:06

I have this DOM:

var id = 0;

$(\'input:file#upload\')[0].files[ id ]

That get\'s the first file on the 0th index. File properties are list

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-01 17:02

    I have found very quick & short workaround for this. Tested in many popular browsers (Chrome, Firefox, Safari);

    First, you have to convert FileList to an Array

    var newFileList = Array.from(event.target.files);
    

    to delete the particular element use this

    newFileList.splice(index,1);
    

提交回复
热议问题