添加参考
http://lucky.diy.myrice.com/javascriptexam/addelement.htm
http://msdn.microsoft.com/workshop/author/tables/buildtables.asp删除可以document.all.myTable.deleteRow(document.all.myTable.rows.length)

解决方案 »

  1.   

    给你个代码
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>test</title>
    <script>
    var k=1
    function doAdd()
    {
    k=k+1;
    var nowTable=document.all.myTable;
    var newTr=nowTable.insertRow(k);
    var newTd=newTr.insertCell(0);
    var newTd1=newTr.insertCell(1);
    var newTd2=newTr.insertCell(2);
    var newTd3=newTr.insertCell(3);
    var newTd4=newTr.insertCell(4);
    var newTd5=newTr.insertCell(5);newTd.innerHTML="<input name='object0' type='text' class='text1' id='object'>";
    newTd1.innerHTML="<input name='object1' type='text' class='text4' id='object1' onKeypress='return(!event.shiftKey&&event.keyCode>47 && event.keyCode<58 )'>";
    newTd2.innerHTML="<input name='object2"+k+"' type='text' class='text2'   onBlur='xx()' id='object2"+k+"' onKeypress='return(!event.shiftKey&&event.keyCode>45 && event.keyCode<58 )'>";
    newTd3.innerHTML="<input name='object3"+k+"'  type='text' class='text2' id='object3"+k+"' onKeypress='return(!event.shiftKey&&event.keyCode>47 && event.keyCode<58 )'>";
    newTd4.innerHTML="<input name='object4' type='text' class='text3' id='object4' value='册' readonly=''> ";
    newTd5.innerHTML="<input name='object5' type='text' class='text1' id='object5'>";
    }
    function doDel()
    {
    if(k>=2)
    {
    document.all.myTable.rows(k).removeNode();
    document.getElementById("object2"+k).name="";
    k=k-1;
    }
    else
    {
    alert("不能继续删减条目!");
    }
    }
    </script>
    <script language="vbscript">
    sub xx()
    m=0
    if k=1 then 
    document.form1.kkk.value=document.getElementById("object21").value
    else
    for n=1 to k
    m=m+document.getElementById("object2"&cstr(n)).value
    next
    document.form1.kkk.value=m
    end if
    end sub</script>
    <style type="text/css">
    <!--
    .text1 { border-bottom-width: 0px;
    border-bottom-style: none;
    border-bottom-color: #000000;
    font-size: 12px;
    border-top-width: 0px;
    border-right-width: 0px;
    border-left-width: 0px;
    border-top-style: none;
    border-right-style: none;
    border-left-style: none;
    background-color: #FFFFEC;
    height: 14px;
    width: 135px;
    }
    .text2 { border-bottom-width: 0px;
    border-bottom-style: none;
    border-bottom-color: #000000;
    font-size: 12px;
    border-top-width: 0px;
    border-right-width: 0px;
    border-left-width: 0px;
    border-top-style: none;
    border-right-style: none;
    border-left-style: none;
    background-color: #FFFFEC;
    height: 14px;
    width: 80px;
    }
    .text3 { border-bottom-width: 0px;
    border-bottom-style: none;
    border-bottom-color: #000000;
    font-size: 12px;
    border-top-width: 0px;
    border-right-width: 0px;
    border-left-width: 0px;
    border-top-style: none;
    border-right-style: none;
    border-left-style: none;
    background-color: #FFFFEC;
    height: 14px;
    width: 28px;
    }
    .text4 { border-bottom-width: 0px;
    border-bottom-style: none;
    border-bottom-color: #000000;
    font-size: 12px;
    border-top-width: 0px;
    border-right-width: 0px;
    border-left-width: 0px;
    border-top-style: none;
    border-right-style: none;
    border-left-style: none;
    background-color: #FFFFEC;
    height: 14px;
    width: 125px;
    }
    -->
    </style>
    </head>
    <body>
    <button  id="manu3" onClick="doAdd();"><img src="images/icon/base/MISC05.ICO" width="15" height="15" align="absmiddle">&nbsp;增行</button>
    <button  id="manu4" onclick="doDel();xx()"><img src="images/icon/base/MISC06.ICO" width="15" height="15" align="absmiddle">&nbsp;删行</button>
    <form name="form1">
    <table width="658" border="1" cellpadding="0"  cellspacing="1" bordercolor="#A0A0A0" id="myTable">
      <tr align="center" valign="middle">
        <td width="147" height="18">aaaaaaaa</td>
        <td width="130" height="18">bbbbbbbb</td>
        <td width="85" height="18">cccccccc</td>
        <td width="85" height="18">ddddddd</td>
        <td width="30" height="18">eeeeeee</td>
        <td height="18">ff</td>
      </tr>
      <tr align="left" valign="middle"  id="myTr1">
        <td height="18"><input name="object0" type="text" class="text1" id="object0"  ></td>
        <td height="18"><input name="object1" type="text" class="text4" id="object1"   onKeypress="return(!event.shiftKey&&event.keyCode>47 && event.keyCode<58 )"></td>
        <td height="18"><input name="object21" type="text" class="text2" id="object21"  onBlur="xx()" onKeypress="return(!event.shiftKey&&event.keyCode>45 && event.keyCode<58)" ></td>
        <td height="18"><input name="object31" type="text" class="text2" id="object31"   onKeypress="return(!event.shiftKey&&event.keyCode>47 && event.keyCode<58 )"></td>
        <td width="30" height="18"><input name="object4" type="text" class="text3" id="object4"  value="" readonly=""></td>
        <td height="18"><input name="object5" type="text" class="text1" id="object5"  ></td>
      </tr>
    </table>
    <p>ccccc求和
      <input type="text" name="kkk">
    </p>
    </form>
    </body>
    </html>