Home >Web Front-end >JS Tutorial >Dynamically operate table through js (add, delete related column information)_javascript skills
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);