Home >Web Front-end >JS Tutorial >How to clear the table using javascript_javascript skills

How to clear the table using javascript_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:59:062676browse

The example in this article describes how to clear the table using javascript. Share it with everyone for your reference. The details are as follows:

1. Normal method

Loop through the rows of the table and delete them one by one.
This method is a common method and is feasible, but it is not efficient.

2. Another method

var artTable = document.getElementById("artical_table"); 
console.debug(artTable.getElementsByTagName("thead")[0]);
var artBody=artTable.tBodies[0];
//clear table
//artBody.innerHTML='';
//获取tbody,清除innerHTML来达到清除表格数据,会报错
artBody.parentNode.outerHTML = artBody.parentNode.outerHTML.replace(artBody.innerHTML, "");
//解决tbody的innerHTML只读问题,这种也会有问题,会导致后面动态插入的行没有

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn