删除 HTML 表格中的所有行 [英] Delete all rows in an HTML table
问题描述
如何使用 Javascript 删除 HTML 表中除 How can I delete all rows of an HTML table except the 将 Keep the 即 这篇关于删除 HTML 表格中的所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! 之外的所有行,并且不循环遍历表中的所有行?我有一个非常大的表,我不想在遍历行以删除它们时冻结 UI
<th>
's using Javascript, and without looping through all the rows in the table? I have a very huge table and I don't want to freeze the UI while I'm looping through the rows to delete them推荐答案
行保留在 中,其他行保留在
然后用一个新的空的替换
.
<th>
row in a <thead>
and the other rows in a <tbody>
then replace the <tbody>
with a new, empty one.var new_tbody = document.createElement('tbody');
populate_with_new_rows(new_tbody);
old_tbody.parentNode.replaceChild(new_tbody, old_tbody)
登录
关闭