にクローニングしながら、どのように私はこのコードjQueryの
$('.cloneMe').on('click', function(e) {
var idToAppend = $(this).data('id');
$(this).data('id', idToAppend + 1);
$('div.render-form-editlayout-10').clone("").find('[id]').attr('id', function(idx, val) {
var newId = (this.name == undefined) ? val + idToAppend : this.name + '_' + idToAppend;
if ((this.name != undefined)) {
$(this).attr('name', newId);
console.log('For elements with name the new ID is: ' +
newId + ' new Name is: ' + newId);
}
return newId;
}).closest('div.render-form-editlayout-10').insertBefore(this);
})
を持っており、私のjsfiddleは、あなたはそれが初めて正常に動作プラスボタンをクリックするとthis
である、しかし、最初に選択します次回は複数のクローンを作成しています。他のロジックを変更せずに修正できますか?
おかげ
私は '+'を押すたびにクローン1を返します。 –
このすべてのデータIDはどういう意味ですか?前回のフィドルで間違ったクローニングを修正しましたが、私の答えを提出する前に、新しいものに変更しました。 – hallleron
@hallleronそれは間違ったフィドルソリでした。 – Vikram