Home >Web Front-end >JS Tutorial >Dynamically operate table through js (add, delete related column information)_javascript skills

Dynamically operate table through js (add, delete related column information)_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:53:22888browse

1. Get the table object
var objTable=document.getElementById( "tb_visitor" );
2. Add a new row
var objTempRow = objTable.rows[0]; //Get the template row
var objNewRow = objTable.insertRow( objTable.rows.length );
objNewRow.id = objTable.rows.length-1;
//Add relevant information of a row 
for ( var i=0 ; i {
var objNewCell = objNewRow.insertCell( i );
objNewCell.innerHTML = objTempRow.cells[i].innerHTML;
//
if(objNewCell.innerHTML.indexOf("value=")!=-1){
var si=objNewCell.innerHTML.indexOf("value=")*1 6;
var ei=objNewCell.innerHTML. indexOf(">");
var cellvalue=objNewCell.innerHTML.substring(si,ei);
//Clear the content of the new column and make it available
objNewCell.innerHTML=objNewCell.innerHTML. replace(cellvalue,'').replace('disabled','');
}
}
//Add row click event
objNewRow.onclick = new Function("fn_clickrow(this );");
3. Delete a row
objTable.deleteRow(objrow.index);

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