有如下代码,想在动态添加一行后,在每一行后面 出现删除按钮,点击这个按钮可以删除该行。麻烦将代码修改一下。谢谢!新手,见谅!<html>
<TABLE border="0" width="50%" id="activeTable1"></TABLE>
  <p>
 <input type="button" name="Submit3" value=" 增 加 备 件 " onclick="AddRecord1()" >
  <script> function getback(obj)
  {
     var td = obj.parentNode;
     var dangjia = td.previousSibling.firstChild;
     var shuliang = td.previousSibling.previousSibling.firstChild;
     obj.value = (shuliang.value * dangjia.value).toFixed(2);
}  
  function AddRecord1()  
  {  
      var row = activeTable1.insertRow(activeTable1.rows.length);//id=recordTable  
      var col = row.insertCell(0);  
      var i = row.rowIndex;  
      col.innerHTML = "<input type='text' name='texth' value=''>"; 
      col = row.insertCell(1);  
      col.innerHTML = "<input type='text' name='texti' value=''>"; 
      col = row.insertCell(2);  
      col.innerHTML = "<input type='text' name='textj' value=''>";
      col = row.insertCell(3);  
      col.innerHTML = "<input type='text' name='textk' onClick='getback(this)'; value=''>";
      col = row.insertCell(4);  
      col.innerHTML = "<input type='hidden' name='textl' value='"+i+ "'>";  
  }  
  </script></html>

解决方案 »

  1.   


    <html>
    <TABLE border="0" width="50%" id="activeTable1"></TABLE>
      <p>
     <input type="button" name="Submit3" value=" 增 加 备 件 " onclick="AddRecord1()" >
      <script>   function getback(obj)
      {
      var td = obj.parentNode;
      var dangjia = td.previousSibling.firstChild;
      var shuliang = td.previousSibling.previousSibling.firstChild;
      obj.value = (shuliang.value * dangjia.value).toFixed(2);
    }   
    function delRow(btn){
    var tr = btn.parentNode.parentNode;
    tr.parentNode.removeChild(tr);
    }
      function AddRecord1()   
      {   
      var row = activeTable1.insertRow(activeTable1.rows.length);//id=recordTable   
      var col = row.insertCell(0);   
      var i = row.rowIndex;   
      col.innerHTML = "<input type='text' name='texth' value=''>";  
      col = row.insertCell(1);   
      col.innerHTML = "<input type='text' name='texti' value=''>";  
      col = row.insertCell(2);   
      col.innerHTML = "<input type='text' name='textj' value=''>";
      col = row.insertCell(3);   
      col.innerHTML = "<input type='text' name='textk' onClick='getback(this)'; value=''>";
      col = row.insertCell(4);   
      col.innerHTML = "<input type='hidden' name='textl' value='"+i+ "'><input type='button' value='删除' onclick='delRow(this)' />";   
      }   
      </script></html>
      

  2.   

    <html>
    <TABLE border="0" width="50%" id="activeTable1"></TABLE>
      <p>
     <input type="button" name="Submit3" value=" 增 加 Y 件 " onclick="AddRecord1()" >
    <script>function getback(obj)
      {
      var td = obj.parentNode;
      var dangjia = td.previousSibling.firstChild;
      var shuliang = td.previousSibling.previousSibling.firstChild;
      obj.value = (shuliang.value * dangjia.value).toFixed(2);
    }
    function AddRecord1()
      {
      var row = activeTable1.insertRow(activeTable1.rows.length);//id=recordTable
      var col = row.insertCell(0);
      var i = row.rowIndex;
      col.innerHTML = "<input type='text' name='texth' value=''>";
      col = row.insertCell(1);
      col.innerHTML = "<input type='text' name='texti' value=''>";
      col = row.insertCell(2);
      col.innerHTML = "<input type='text' name='textj' value=''>";
      col = row.insertCell(3);
      col.innerHTML = "<input type='text' name='textk' onClick='getback(this);' value=''>";
      col = row.insertCell(4);
      col.innerHTML = "<input type='hidden' name='textl' value='"+i+ "'>";
      col = row.insertCell(5);
      col.innerHTML = "<input type='button' name='btn1'  onClick='del(this.parentNode.parentNode);' value='del' >";
    }
    function del(o){
      activeTable1.childNodes[0].removeChild(o);
    }
    </script></html>