jQuery清除多个输入文件的特定值

时间:2018-04-04 09:23:35

标签: javascript jquery html upload

我上传了多个选择的文件表单。

<span class="btn btn-default btn-file">
    Browse <input type="file" name="image[]" id="image" onchange="preview_image();" multiple/>
</span>

<div class="image_preview"></div>

然后在选择文件后,它将显示图像缩略图预览,并为每个图像显示删除操作。

function preview_image() 
{
    var total_file = document.getElementById("image").files.length;

    if($("#totalImageList").val() == "")
    {
        var totalImageList = 0;
    }
    else
    {
        var totalImageList = $("#totalImageList").val();
    }

    var total = parseInt(total_file)+parseInt(totalImageList);

    $(".uploadError").hide();

    if((total) < 6)
    {
        $("#totalImageList").val(total);

        for(var i=0;i<total_file;i++)
        {
            $('.image_preview').append("<div class='imageList'><img src='"+URL.createObjectURL(event.target.files[i])+"'/><div class='removeImage'>Remove</div></div>");

            $(".removeImage").click(function()
            {
                $(this).parent(".imageList").remove();

                $("#totalImageList").val($(".imageList").length);
            });
        }
    }
    else
    {
        $(".uploadError").show();
    }
}

请看下图: enter image description here

现在我希望当我点击图片特定的删除时,它只会清除特定图片的值删除点击。

怎么做?

1 个答案:

答案 0 :(得分:0)

要删除点击图片,只能按以下方式执行。

&#13;
&#13;
$('.removeImage').on('click', function(){
  $(this).parent().remove();
});
&#13;
&#13;
&#13;

相关问题