2015-07-20 64 views
-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'); 
+0

我不明白你在這裏尋求什麼幫助? – Ajaypayne

+0

檢查更新... – Higeath

+0

好的,你試圖在那裏實現什麼?看起來你只是在下一個實例上增加了id,在小提琴中工作正常。 – Ajaypayne

回答

0
目標占位符

您不能定位已移除的元素,因爲它不再存在。您必須重新創建它才能重新定位。

作爲一個附註,您可以定位您隱藏的元素。

+0

$(this).siblings('ChampionInput')。next() .attr('placeholder','test');我想針對下一個冠軍輸入和即時消息使用此之前刪除 – Higeath