论坛首页 入门技术论坛

js 增加行

浏览 1183 次
锁定老帖子 主题:js 增加行
该帖已经被评为隐藏帖
作者 正文
   发表时间:2009-01-12   最后修改:2009-01-12
<table id="testTbl" border=1> 

<tr id="tr1"> 
<td >第一行</td> 
<td >第一行</td> 
<td >第一行</td> 
<td >第一行</td> 
</tr> 

</table> 

动态添加表行的javascript函数如下: 

<script language="javascript"> 

function addRow(){ 

//添加一行 

var newTr = testTbl.insertRow(); 

//添加列 

var newTd0 = newTr.insertCell(); 
var newTd1 = newTr.insertCell(); 
var newTd2 = newTr.insertCell(); 
var newTd3 = newTr.insertCell(); 

//设置列内容和属性 

newTd0.innerHTML = '新增加的行'; 
newTd1.innerText= '新增加的';
newTd2.innerText= '新增加的';
newTd3.innerText= '新增加的';
}
</script> 

<BR>
<a href="#" onclick="addRow();">增加</a> 
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics