会员
周边
众包
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
让心灵去旅行
幸福是旅程,而不是终点
博客园
首页
新随笔
联系
订阅
管理
动态添加和删除行
<
html
>
<
head
>
<
title
>
动态添加和删除行
</
title
>
<
script
type
="text/javascript"
>
<!--
var
count
=
1
;
var
nRows
=
2
;
function
addRow()
{
var
tBody
=
document.getElementById('theBody');
var
newRow
=
document.createElement('tr');
var
col1
=
document.createElement('td');
var
col2
=
document.createElement('td');
var
col3
=
document.createElement('td');
var
rA
=
document.createElement('a');
newRow.setAttribute('id', 'n'
+
count);
rA.setAttribute('href', 'javascript:removeRow(\'n'
+
count
+
'\');');
rA.appendChild(document.createTextNode('Remove'));
col1.appendChild(document.createTextNode('Col
1
Row '
+
nRows));
col2.appendChild(document.createTextNode('Col
2
Row '
+
nRows));
col3.appendChild(rA);
newRow.appendChild(col1);
newRow.appendChild(col2);
newRow.appendChild(col3);
tBody.appendChild(newRow);
count
++
;
nRows
++
;
}
function
removeRow(rowId)
{
var
tBody
=
document.getElementById('theBody');
tBody.removeChild(document.getElementById(rowId));
nRows
--
;
}
-->
</
script
>
</
head
>
<
body
>
<
table
>
<
tbody
id
="theBody"
>
<
tr
>
<
td
>
Col 1 Row 1
</
td
>
<
td
>
Col 2 Row 1
</
td
>
</
tr
>
</
tbody
>
</
table
>
<
p
><
a
href
="javascript:addRow()"
>
Add Row
</
a
></
p
>
</
body
>
</
html
>
posted @
2005-07-01 14:47
让心灵去旅行
阅读(
717
) 评论(
0
)
编辑
收藏
举报
刷新页面
返回顶部
公告