我正在嘗試創建一個表,在其中輸入對象中的元素??梢栽陧撁嫔铣尸F的元素數量有限。因此,為了查看更多內容,您將單擊下一個/上一個,以查看其他“頁面”。問題是,我想刪除不顯示的索引。底部的邏輯是我設置最小和最大索引并查看不同的頁面,我會將這些數字增加 10(以在頁面上獲得 10 個結果),但是當我單擊下一步按鈕時,我想刪除 0 - 10 和只有 10 - 20 個,但 table.deleteRow(index) 不執行任何操作。(但 table.deteteRow(1) 確實有效)function fill(){ prices.forEach((element,index) =>{ const table = document.querySelector("table"); const tr = document.createElement("tr"); tableItems.appendChild(tr); if(index >= min && index < max){ const type = document.createElement("td"); const name = document.createElement("td"); const hours = document.createElement("td"); const photos = document.createElement("td"); const place = document.createElement("td"); const price = document.createElement("td"); type.innerHTML = element.type; name.innerHTML = element.name; hours.innerHTML = element.hours; photos.innerHTML = element.photos; place.innerHTML = element.place; price.innerHTML = element.price; tr.appendChild(type); tr.appendChild(name); tr.appendChild(hours); tr.appendChild(photos); tr.appendChild(place); tr.appendChild(price); } if(index > max){ table.deleteRow(index); } // }); } buttonRight.addEventListener("click",()=>{ min = max; max = max + 10; fill(); }); buttonLeft.addEventListener("click",()=>{ max = min; min = min -10; fill(); });
無法刪除帶有索引的表內的 tr 元素
慕少森
2023-09-28 17:00:07