我正在使用clone属性创建动态页面。
当我创建4个Assured元素时,当我关闭第一个Assured(即) Assured 1 时,会出现问题,根据 nth-element <多次出现close if语句/ strong>价值(希望如此)。
我希望只发生一个循环,以便 id - 只出现一次......
cell.layoutIfNeeded()
&#13;
$(document).ready(function() {
var id = 1;
var assured = document.getElementById('assuredconb');
$('.add-contact').click(function(e) {
e.preventDefault();
if (id < 5) {
$(this).closest('li').before('<li><a data-toggle="tab" href="#assured' + id + '">New assured ' + id + '</a><span class="fas fa-times-circle close" id="close' + id + '"></span></li>');
var clone = assured.cloneNode(true);
clone.id = "assured" + id;
$('.tab-content').append(clone);
id++;
}
$('.close').click(function() {
id--;
var anchor = $(this).siblings('a');
$(anchor.attr('href')).remove();
$(this).parent().remove();
$(".nav-tabs li").children('a').first().click();
alert(id);
});
});
});
&#13;
.close {
color: red;
opacity: 0.8;
position: absolute;
right: 5%;
top: 25%;
}
.nav-tabs>li>a {
width: 175px;
text-align: center;
}
.add-contact {
width: 50px !important;
}
&#13;