【问题标题】:Javascript - remove image selected from input file [duplicate]Javascript - 删除从输入文件中选择的图像[重复]
【发布时间】:2017-04-19 02:01:38
【问题描述】:

我正在使用输入文件图像“预览/删除”功能,但我在删除图像选择功能时发现此错误:

拼接不是函数(…)

点击删除我有这个代码:

HTML:

<input id="pictures" type="file" class="inputfile" name="image[]" multiple required>

JS

$('body').on('click', '.removeImage', function(e){

                e.stopImmediatePropagation();
                // name file removed
                var namefileRemoved = $(this).parent().parent()[0].id;
                // get array images selected
                var elm=$('#pictures')[0].files; 
                // get position element in array and delete it.
                for(var i = 0; i < elm.length; i++) {
                   if(elm[i].name === namefileRemoved) {
                     elm.splice(0, i);
                   }
                }
                // remove image display html
                $(this).parent().parent().parent().remove();
});

我的var elm=$('#pictures')[0].files; 返回

我试图搜索类似的问题,但我没有找到解决方案!感谢您的帮助!

【问题讨论】:

  • 正如您在日志中看到的那样,对象不是Array 类型,而是FileList 类型,因此拼接不工作。
  • 这是关于从 FileList 中删除文件的答案的链接。 stackoverflow.com/questions/3144419/…

标签: javascript jquery html


【解决方案1】:

尝试切片而不是拼接。我怀疑这就是问题所在。

【讨论】:

    猜你喜欢
    • 2020-01-17
    • 1970-01-01
    • 2016-10-16
    • 1970-01-01
    • 1970-01-01
    • 2011-08-31
    • 2017-07-11
    • 2014-07-15
    • 2023-03-12
    相关资源
    最近更新 更多