我一直在嘗試找出如何刪除特定的“li”標簽,方法是根據其在列表中的位置輸入其編號(即在文本框中輸入 3,然后按按鈕刪除列表位置 3 中的項目) )?,F在我的代碼是這樣的,即使只列出了 4 個項目,輸入 5 并按 Enter 鍵仍然會刪除 2 個項目,而不是不刪除任何項目。我的代碼編寫方式與刪除特定“li”標簽時鍵入的數字不一致。任何幫助將不勝感激,謝謝。<html><head><title>Chapter 5 Activity</title></head><body><h1>The Best Fruit in the World</h1><ol id="fruit"> <li>Mangos</li> <li>Watermelons</li> <li>Kiwis</li> <li>Pineapples</li></ol><form action=""><input type="text" name="rfruit" id="fruitremove"> <input type="button" value="Click to Remove" onclick="removefruit()"> Remove fruit you dislike</form><script type="text/javascript">function removefruit(){ var fruitminus = document.getElementById("fruitremove").value; var flist = document.getElementById("fruit"); flist.removeChild(flist.childNodes[fruitminus]);}</script></body></html>
如何通過文本根據訂單號刪除特定的 Li 標簽?
函數式編程
2023-07-20 17:19:48