您的位置:首页 > Web前端 > HTML

在table中插入多行,能使用与insertAdjacentHTML相似的功能

2010-06-22 21:18 561 查看
<html>
<body>
<table id=tableList border=1 width=100>
<tr><td>1</td></tr>
</table>
<button onclick=addRow()>插入行</button>
</body>

<script type="text/javascript">
var num = 1;
function addRow()
{
num ++;
InsertRow(tableList,"<tr><td>"+num+"新行</td></tr>");
}
function InsertRow(table,rowHtml)
{
var o=document.createElement("div"),ol;
o.innerHTML="<table>"+rowHtml+"</table>"
ol=o.childNodes[0].tBodies[0].rows
while(ol.length>0){
table.tBodies[0].appendChild(ol[0])
}
}
</script>

Table的 tBodies属性是一个JS中的集合,而不是数组,没有sort()方法,所以不能用来直接排序。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐