.layer_star {
display: flex;
justify-content: flex-start;
align-items: center;
}
.one,
.add {
width: 120px;
height: 120px;
border: 1px solid #f2f2f2;
margin-left: 20px;
position: relative;
}
.one img {
width: 100%;
height: 100%;
}
.add {
padding: 20px;
box-sizing: border-box;
}
.delete {
width: 20px;
height: 20px;
position: absolute;
top: 5px;
right: 5px;
}
.delete img {
width: 100%;
height: 100%;
}
.add input {
width: 100%;
height: 100%;
top: 0;
left: 0;
position: absolute;
opacity: 0;
}
.add img {
width: 100%;
height: 100%;
}
<div class="layer_star">
<div class="layer_star" id="result" name="result"></div>
<div class="add">
<input
type="file"
name="file"
id="file"
multiple="multiple"
onchange="addUrl()"
/>
<img src="./img/plus.png" alt="" />
</div>
</div>
var file;
var arr = [];
var i = 0;
function addUrl() {
file = document.getElementById("file").files;
var result = document.getElementById("result");
$.each(file, function (k, v) {
arr.push(v);
var reader = new FileReader();
reader.readAsDataURL(file[k]);
reader.onload = function (e) {
result.innerHTML =
result.innerHTML +
'<div class="one" id="' +
file[k].name +
'">' +
"<img src='" +
this.result +
"' alt='' />" +
"<div class='delete' οnclick='deletes(\"" +
file[k].name +
"\")'>" +
"<img src='" +
"./img/shanchu.png" +
"' alt='' />";
"<div/>" + " </div>";
};
});
}
function deletes(e) {
$.each(arr, function (k, v) {
console.log(v);
if (e == v.name) {
arr.splice(k, 1);
k--;
}
});
}