语法:
oTD = TR . insertCell ( iIndex )
参数:
iIndex : 可选项。整数值(Integer)。指定插入 td 的序号。默认值为 -1 ,插入单元格到 cells 集合内的最后一个。
返回值:
oTD : 对象(Element)。成功则返回新建 td 的引用。否则返回 null 。
说明:
在表格行内建立新的单元格( td ),同时添加到 cells 集合内。
推荐使用的方法,是依据默认值将单元格插入到 cells 集合内的最后一个。这是速度最快的插入方式。
<script>
function rdl_doAdd(){
var oBody=document.createElement("<tbody id=myBody>");
document.all("myTable").insertBefore(oBody,document.all("myFoot"));
for (m=0;m<3;m++) {
var myTR =oBody.insertRow();
for (i=0;i<4;i++) {
var myTD=myTR.insertCell();
myTD.innerText="第"+(i+1).toString()+"个单元格";
}
}
document.all("myHeadTD").colSpan=document.all("myFootTD").colSpan=i.toString();
window.resizeTo(320,310);
}
</script>
<table cellspacing=1 id=myTable width=90%>
<thead id=myHead><tr><td id=myHeadTD>这是标题</td></tr></thead>
<tfoot id=myFoot><tr><td id=myFootTD>这是脚注</td></tr></tfoot>
</table>
<br><input type=button value=" 插入TBODY " onclick="rdl_doAdd();">
