私はフィドルから使用しているこのjquery tatを持っています(テストのために自分のサイトで作業するためにそれを使用しています)。
$(document).ready( function() {
var regex = /^(.*)(\d)+$/i;
var cloneIndex = $(".clonedInput").length;
$("button.clone").click(function(e){
$(this).parents(".clonedInput").clone()
.insertBefore(copy)
.attr("id", "clonedInput" + cloneIndex)
.find("*").each(function() {
var id = this.id || "";
var match = id.match(regex) || [];
if (match.length == 3) {
this.id = match[1] + (cloneIndex);
}
});
cloneIndex++;
return false;
});
$("button.remove").click(function(){
$(this).children(".clonedInput").remove();
});
});
おそらく1つの問題が原因である2つの問題は、「複製された」フィールドの1つを削除すると、親以外の他のすべてのフィールドが削除され、フィールドを複製すると、親であり、元の値を保持します...
どんな助けでも大歓迎です!