第一种:insertRow()
语法
tableObject.insertRow(index)
说明
该方法创建一个新的 TableRow 对象,表示一个新的
标记,并把它插入表中的指定位置。
新行将被插入 index 所在行之前。若 index 等于表中的行数,则新行将被附加到表的末尾。
如果表是空的,则新行将被插入到一个新的
段,该段自身会被插入表中。
例子:
function addRow(){
//添加一行(testTbl是html页面中要加如行的table的id)
var newTr = testTbl.insertRow();
//添加两列
var newTd0 = newTr.insell()ertC;
var newTd1 = newTr.insertCell();
//设置列内容和属性
newTd0.innerHTML = '
id="box4">';
newTd1.innerText= '新加行';
}
第二种:appendChild()
//获取页面中tr对象
var
proid=document.getElementByIdx("pro_id");
//创建td对象
var td=null;
td=document.createElement("td");
//给td加入内容
td.appendChild(document.createTextNode(nodue);
//使td和tr关联起来
proid.appendChild(td);