删除HTML表格中的所有行 [英] Delete all rows in an HTML table

查看:532
本文介绍了删除HTML表格中的所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Javascript删除除< th> 之外的HTML表格的所有行,并且不循环表格中的所有行?我有一个非常大的表,我不想冻结用户界面,而我循环行删除它们。

解决方案

保持< th> >行位于< thead> 中,其他行位于< tbody> 然后用新的空白替换< tbody> 。 b $ b

ie

  var new_tbody = document.createElement('tbody'); 
populate_with_new_rows(new_tbody);
old_tbody.parentNode.replaceChild(new_tbody,old_tbody)


How can I delete all rows of an HTML table except the <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

解决方案

Keep the <th> row in a <thead> and the other rows in a <tbody> then replace the <tbody> with a new, empty one.

i.e.

var new_tbody = document.createElement('tbody');
populate_with_new_rows(new_tbody);
old_tbody.parentNode.replaceChild(new_tbody, old_tbody)

这篇关于删除HTML表格中的所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆