JS 动态给表格增加/删除一行

 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>动态给表格增加/删除一行</title>
</head>
<script language=javascript>
//增加组员
var allCount=1
function addline()
{
 if(allCount<5){
 newRow=listtable.insertRow(listtable.rows.length);
 newRow.ln=allCount;
 newRow.id=allCount;
 c1=newRow.insertCell(0);
 c1.innerHTML="<input type='text' name='stunum"+allCount+"' style='width:80px' />"+
               "<input type='text' name='stuname"+allCount+"' style='width:100px' />";
 c2=newRow.insertCell(1);
 c2.id="line"+allCount;
 c2.innerHTML="<input type=button value=删除 οnclick=delline("+allCount+")>";
 allCount++;
 }else{
	 alert("组员最多不能超过4人!");
 }
}
function delline(lineid)
{
 for(i=0;i<listtable.rows.length;i++)
 {
   if(listtable.rows[i].id==lineid)
   {

        listtable.deleteRow(i);
        allCount--;

   }
 }
}
//增加辅导教师
var allCount1=1
function addtea()
{
 if(allCount1<3){
 newRow=listtea.insertRow(listtea.rows.length);
 newRow.ln=allCount1;
 newRow.id=allCount1;
 c1=newRow.insertCell(0);
 c1.innerHTML="<input type='text' name='teanum"+allCount1+"' style='width:80px' />"+
               "<input type='text' name='teaname"+allCount1+"' style='width:100px' />";
 c2=newRow.insertCell(1);
 c2.id="line"+allCount1;
 c2.innerHTML="<input type=button value=删除 οnclick=deltea("+allCount1+")>";
 allCount1++;
 }else{
	 alert("辅导教师最多不能超过2人!");
 }
}
function deltea(lineid)
{
 for(m=0;m<listtea.rows.length;m++)
 {
   if(listtea.rows[m].id==lineid)
   {	
		listtea.deleteRow(m);
        allCount1--;
   }
 }
}
 </script>

<body>
 <input type=button value=添加组员 οnclick=addline()>前面填学号,后面填姓名,个人项目可不填
 <table  border="0" height=20 align="left" cellpadding=0 cellspacing=0 id=listtable></table>
<br/>
<input type=button value=添加老师 οnclick=addtea()>前面填工号,后面填姓名,没有不填 
<table  border="0" height=20 align="left" cellpadding=0 cellspacing=0 id=listtea></table>
</body>
</html> 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值