Suppose: a piece of ordinary code:
where gift_list is the id of a table
var giftBody = document.getElementById("gift_list").getElementsByTagName("tbody")[0];
var giftTrs = giftBody.getElementsByTagName("tr");
for (var i= 0;i{
giftTrs[i].removeChild(giftTrs[i]);
}
Then only the first child will be deleted at this time One row, because when one is deleted, the position of the row will move forward one position.
giftTrs.length will also be reduced by one accordingly.
So the correct operation method is:
var giftBody = document.getElementById("gift_list").getElementsByTagName("tbody")[0];
var giftTrs = giftBody.getElementsByTagName("tr");
var len = giftTrs.length; //Need to change giftTrs The length attribute of .length is stored
for (var i=0;i{
giftBody.removeChild(giftTrs[0]);
}