Home  >  Article  >  Web Front-end  >  Specific implementation of js dynamically controlling the addition and deletion of tr and td in table_javascript skills

Specific implementation of js dynamically controlling the addition and deletion of tr and td in table_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:50:391217browse

html:

Copy code The code is as follows:














Serial number Machine name IP address MAC address Uplink/Downlink rate


js:

Added:
Copy Code The code is as follows:

if (condition)
{//Distinguish between wireless clients and limited clients based on the value of InterfaceType
var table = document.getElementById("wifi_clients_table");
var newRow = table.insertRow(); //Create a new row

var newCell1 = newRow.insertCell(0); //Create a new cell
newCell1.innerHTML = "1" ; //Content within the cell
newCell1.setAttribute("align","center"); //Set the position

var newCell2 = newRow.insertCell(1); //Create a new cell
newCell2.innerHTML = "" info.LANHosts.HostName "";
newCell2.setAttribute(" align","center"); //Set the position

var newCell3 = newRow.insertCell(2); //Create a new cell
newCell3.innerHTML = "" info.LANHosts .IPAddress "";
newCell3.setAttribute("align","center"); //Set the position

var newCell4 = newRow.insertCell(3); //Create a new Cell
newCell4.innerHTML = "" info.LANHosts.MACAddress "";
newCell4.setAttribute("align","center"); //Set position

var newCell5 = newRow.insertCell(4); //Create a new cell
newCell5.innerHTML = "" info.LANHosts.UpRate "/" info.LANHosts.DownRate "kb";
newCell5.setAttribute("align","center"); //Set the position

}

Delete: Clear when the page is closed, next time Regenerate when accessing to prevent tr from incrementing each time and causing page confusion
Copy code The code is as follows:

var t1=document.getElementById("lan_clients_table");

var rowNum=t1.rows.length;
if(rowNum>0)
{
for(i=0 ;i{
t1.deleteRow(i);
rowNum=rowNum-1;
i=i-1;
}
}
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