<html>
<body>
<script language="javascript">
<!--
function additem(id)
{
  var row,cell,str;
  row = document.getElementById(id).insertRow();
  if(row != null )
  {
cell = row.insertCell();
cell.innerHTML="<input type=\"text\" name=\"StuName\"><input type=\"button\" value=\"删除\" onclick=\'deleteitem(this);\'>";
  }
}
function deleteitem(obj)
{
  var curRow = obj.parentNode.parentNode;
  tb.deleteRow(curRow.rowIndex);
}
//-->
</script>
<form name="form" method="post" action="addrow.php">
<table id="tb"></table>
<input name="button" type=button onClick='additem("tb")' value="添加>>"><input type="submit" name="submit" value="提交">
</form>
</body>
</html>
这样添加的每个文本框的name是一样的,要是添加不同name的文本框怎么做???(要方便提交后获取值)

解决方案 »

  1.   

    var i=0 全局变量
    每执行一次additem(id) i++
    然后改这句
    cell.innerHTML="<input type=\"text\" name=\"StuName'"+i+"'\"><input type=\"button\" value=\"删除\" onclick=\'deleteitem(this);\'>";
      

  2.   

    加个ID控制下就可以了<!--
    var id=0;
    function additem(id)
    {
      var row,cell,str;
      row = document.getElementById(id).insertRow();
      if(row != null )
      {
    id++;
             cell = row.insertCell();
    cell.innerHTML="<input type=\"text\" name=\"StuName"+ id +"\"><input type=\"button\" value=\"删除\" onclick=\'deleteitem(this);\'>";
      }
    }
      

  3.   

    //要方便提交后获取值name相同也方便地可以得值,只不过获取到的是一串被","分隔开的字符串
      

  4.   

    Roby610(雨哲)朋友,那我提交后怎么知道一共添加了多少个文本框?for循环范围怎么写?php程序
      

  5.   

    你可以加一隐藏控件来记录这id 的值,这样就可以知道添加了多少duwa789 说的也是,只要split一下就知道有多少了
      

  6.   

    你还有deleteitem,这样id就不能保证连续了,处理起来似乎难一些另:PHP我不懂
      

  7.   

    php页面接收的name相同的文本框的值并不是一串被","分隔开的字符串啊,而是最后一个文本框的值啊,那有其他办法解决吗?