私のデモは非常に明確です。要素のクローンを作成するときは、divのクローンを作成して削除しますが、:last要素(li)は削除しないでください。私が欠けているものは何ですか?
これと関係があります!:
$(document).on("click", 'li.delete',function () {
$(this).closest(".outerDiv").remove();
if ($(this).is(".outerDiv:last")){
return false;
}
デモ:http: //jsfiddle.net/XeELs/86/
JQUERY var cloneCount = 0; $( "#add-address")。click(function(){
$("#to-add-address").clone()
.attr("id", "to-add-address_Clone" + cloneCount)
.insertAfter("#to-add-address");
$("#clone", "#to-add-address_Clone" + cloneCount)
.attr("id", "clone_Clone" + cloneCount);
cloneCount++;
});
$(document).on("click", '.options li a',function () {
$(this).closest(".options").find('li a').removeClass('selected');
$(this).addClass('selected');
});
$(document).on("click", 'li.delete',function () {
$(this).closest(".outerDiv").remove();
if ($(this).is(".outerDiv:last")){
return false;
}
});