Through JS dynamic operation table (add, delete related column information) _javascript tips
Source: Internet
Author: User
1. Get the Table object
var Objtable=document.getelementbyid ("Tb_visitor");
2, add a line
var objtemprow = objtable.rows[0]; Get Template Line
var objnewrow = Objtable.insertrow (objTable.rows.length);
Objnewrow.id = objtable.rows.length-1;
Add related information for a row
for (var i=0; i<objtemprow.cells.length; 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);
Empty new column contents and become available
Objnewcell.innerhtml=objnewcell.innerhtml.replace (Cellvalue, '). Replace (' disabled ', ');
}
}
Add a line Click event
Objnewrow.onclick = new Function ("Fn_clickrow (this);");
3, delete a row
Objtable.deleterow (Objrow.index);
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.