if you really care about index, add a hidden input to your form, get all the remaining indexes and merge them and set the value to the hidden input

解决方案 »

  1.   

    function form_submit()
    {
      var e = event.srcElement;
      
      var s = "";
      for (var i=0; i < table1.rows.length; i++)
      {
    var att = table1.rows[i].getAttribute("id");
    if (att != null)
    {
    var n = att.indexOf("row");
    if (n >=0)
    s += "," + att.substring(n+3); 
    }
      }  if (s.length > 0)
    s = s.substring(1);  alert(s);  e.form.indexlist.value = s; 
    }on the server side, you can dos = request.form("indexlist")
    a = split(s,",")
    for n=0 to ubound(a)
      a(n) 'is one of the indices remaining
    next
      

  2.   

    http://www.csdn.net/Develop/Read_Article.asp?Id=8652
      

  3.   

    其实在Delete_Row方法里把每行的index--就行了,我式过了,应该可以,<html>
    <META http-equiv=Content-Type content="text/html; charset=gb2312">
    <SCRIPT language=javascript>
    var rowIndex = 0;
        function openW(v) {
         alert("当前行的index="+v);  //怎么能获得当前选中行的index;
        }
        
        function addOneLine_onClick() {
    var row=table1.insertRow(table1.rows.length);
    var col = row.insertCell(0);
    col.innerHTML = "<input id=fphm name=fphm size=8 maxlength=5>";
    col = row.insertCell(1);
    col.innerHTML = "<INPUT maxLength=6 size=10 name=ys><INPUT type=button  value =...   name=selectys index=\""+ rowIndex +"\" onclick=\"openW(this.index)\">";
    col = row.insertCell(2);
    col.innerHTML = "<input id=fdjh name=fdjh size=10 maxlength=10>";
    col = row.insertCell(3);
    col.innerHTML = "<input id=fdjh name=fdjh size=10 maxlength=10>";
    col = row.insertCell(4);
    col.innerHTML = "<input type='button' value='删除一行' id=btnDeleteLine name=btnDeleteLine onclick=\"return Delete_Row('row" + rowIndex + "')\">";
    row.setAttribute("id", "row" + rowIndex);
    row.setAttribute("name", "row" + rowIndex);
    rowIndex++;
    }

    function Delete_Row(rowTag){
    var i = table1.rows(rowTag).rowIndex;
    var j;
    for(j=i;j<=rowIndex;j++)
    {
    table1.rows(j).cells(1).all("selectys").index--;

    }

            table1.deleteRow(i);
    rowIndex--;
    alert(rowIndex);
           
    }
    </SCRIPT><META content="MSHTML 5.50.4134.600" name=GENERATOR></HEAD>
    <BODY bgColor=#ffffff>
    <DIV align=center>
    <FORM name=form1 action="" method=post>
    <TABLE id=table1 height=23 cellSpacing=2 cellPadding=2 width=600 border=0>
      <TBODY>
      <TR>
        <TD width=70 height=18>
          <DIV align=left>发票号</DIV></TD>
        <TD width=119 height=18>
          <DIV align=left>商品车颜色</DIV></TD>
        <TD width=89 height=18>
          <DIV align=left>发动机号</DIV></TD>
        <TD width=93 height=18>
          <DIV align=left>底盘号</DIV></TD>
        <TD width=76 height=18>
          <DIV align=left>删除</DIV></TD></TR></TBODY></TABLE>
    <SCRIPT language=javascript>
         addOneLine_onClick();
        </SCRIPT>
    <P><INPUT onclick="return addOneLine_onClick()" type=button value=加入一行 name=btnAddLine> 
    <INPUT onclick=form_submit() type=button value=保存 name=btnSave> <INPUT onclick=form_reset() type=button value=重置 name=btnReset> </P>
    <P>&nbsp;</P>
    <P>&nbsp;</P></FORM>
    <P>&nbsp;</P></DIV></BODY></HTML>
    </html>