1、首先在代码加载完之后,遍历一个标签内的所有img标签,给这些标签全都带上“id”
代码参考:https://zhidao.baidu.com/question/2117550140413534267.html
$("#img_box img").each(function(i,e){
$(this).attr('id','remove_' + i)
})
下面的代码是灵感来源……
obj.preview(function (index, file, result) {
$(".layui-upload-list").append('<img src="' + result + '" id="remove_' + index + '" title="双击删除该图片" style="width:200px;height:auto;">')
//console.log(1, index); //得到文件索引
//console.log(2, file.name); //得到文件对象
//console.log(3, result); //得到文件base64编码,比如图片
})
2、接下来就是绑定双击删除图片事件
$('#remove_' + index).bind('dblclick', function () {//双击删除指定预上传图片
delete files[index];//删除指定图片
$(this).remove();
})
思绪来源于:https://blog.csdn.net/qq_36894527/article/details/89385264