Discuss / JavaScript / 降序删除就可以了

降序删除就可以了

Topic source

龙族疯少

#1 Created at ... [Delete] [Delete and Lock User]

降序删除就可以了

var li = document.getElementById("test-list");
for(let i = li.children.length; i>=0; i--){
    var self = li.children[i];
    if(i === 1 || i === 3 || i===5)
    li.removeChild(self);
}

for(let i=li.children.length-1; i>=0; i--) 降序是好思路,但是index要从length-1开始


  • 1

Reply