表格动态添加行操作



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
/*
动态添加table.将table中的text的值存入另一text中,在后台得到另一text的值
注意:1。OnChanged将“text的值存入另一text中”。如果此事件写入后台代码,将得不到。因为被postback掉了。
故先存,再运行后台代码。
2。在html中有一table,名字为filetb。
如果需要动态修改,在table里添加literal.text.
*/
var allCount;
allCount=0;
function addAttachment() {

allCount++;
var Num,p,myrow,indexnewrow,c1,c2,c3;
var rown=filetb.rows.length;

myrow=filetb.insertRow(rown-1);
myrow.id="tdt"+allCount;
myrow.name="tdt"+allCount;
myrow.className="smallFont";

c1=myrow.insertCell();
c1.width="100";
c1.align="right";
c1.innerHTML="<p align=right>代码" + (allCount) + ":";

c2=myrow.insertCell();
c2.align="left";
c2.innerHTML="<INPUT type='text' onchange='return GetValue()' style='width:200' class=t1 name=txtCode"+(allCount)+" MaxLength='50'>";

c3=myrow.insertCell();
c3.align="left";
c3.innerHTML="   <a href='javascript:removeatt(" + allCount + ");'>删除</a>";

}

function GetValue()
{
var id;
var a;
var b;
for(i=0;i<filetb.rows.length;i++)
{
a = filetb.rows(i).cells(0).innerText;
a = a.substring(2,3);
id = "txtCode" + a;
document.all("txt").value += document.all(id).value;
}
}

function removeatt(ln)
{
var i
var tdname
var tdln
var line=ln;
if (line>0) {
for (i=0;i<filetb.rows.length;i++) {
tdname=filetb.rows[i].name;
tdln=tdname.substring(3,tdname.length);
if (tdln==line) {
filetb.deleteRow(i);
break;
}
}
}
}
</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="" runat="server">
<input type=button onclick="return addAttachment()" id=btnNew value=click />
<input type=button onclick="return GetValue()" id=btnGet value=GetValue />
<input type="text" id=txt />
<table id=filetb border="1"></table>

</form>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值