-1
所以現在我在移除錨後有'冠軍'輸入,並且出於某種原因,我無法以任何方式通過Jquery來定位它。下面的代碼是最重要的部分。動態地改變輸入的值
這裏同時工作的jsfiddle:http://jsfiddle.net/x97uLkhp/
championNumberArray = 0;
championNumber = 1;
$('a#AddChampion').on('click',function(){
$('div#ChampionInput').append(
'<div class="Champion" data-id="'+championNumberArray+'">\
<a href="#" class="Remove">Remove</a>\
<br>\
<input type="text" class="ChampionInput" list="champions" name="champion[]" placeholder="Champion '+championNumber+'">\
<datalist id="champions"></datalist>\
<a href="#" class="AddSpell">Add Spell</a>\
<a href="#" class="AddGeneralChange">Add General Change</a>\
<div class="GeneralChanges">\
</div>\
<div class="SpellChanges">\
</div>\
<br>\
<div>');
for(var key in champions){
if(champions.hasOwnProperty(key)){
$('#champions').append('<option value="' + key + '">');
}
}
championNumberArray++;
championNumber++;
});
$('div#ChampionInput').on('click', 'a.Remove',function(){
var champion = $(this).closest('.Champion');
var id = champion.data("id");
var nextChampion = champion;
while((nextChampion = nextChampion.next()).length != 0){
$(this).siblings('ChampionInput').attr('placeholder', 'test');
nextChampion.attr("data-id",id++);
}
championNumberArray=id;
champion.remove();
});
UPDATE:我想,我不能在這裏的一些原因是該行我想執行
$(this).siblings('ChampionInput').attr('placeholder', 'test');
我不明白你在這裏尋求什麼幫助? – Ajaypayne
檢查更新... – Higeath
好的,你試圖在那裏實現什麼?看起來你只是在下一個實例上增加了id,在小提琴中工作正常。 – Ajaypayne