簡體   English   中英

有沒有.cloneNode的對立面?

[英]Is there an opposite of .cloneNode?

我正在編寫一個食譜網站提交表單,並在表單中使用此代碼增加成分的數量。

addIngredientsBtn.addEventListener('click', function(){
    let newIngredients = ingredientDiv.cloneNode(true);
    let input = newIngredients.getElementsByTagName('input')[0];
    input.value = '';
    ingredientList.appendChild(newIngredients);
}); 

如何扭轉這一點以從表單中刪除節點? 謝謝你的幫助

添加每個節點時,您可以執行以下操作:

newIngredients.addEventListener('click', function(){
   this.parentNode.removeChild(this);
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM