javascript动态添加删除表格

<html>
<meta http-equiv="Content-Type" c />
<head>
<script language="javascript">
  function deleteRow(index)
  {
    var tableObj=document.getElementById("mytable");
    tableObj.deleteRow(tableObj.rows.length-1);
  }
  function addRow()
  {
     var tableObj=document.getElementById("mytable");
     var newRowObj=tableObj.insertRow(tableObj.rows.length);
     var newColName=newRowObj.insertCell(newRowObj.cells.length);
     var newColAge=newRowObj.insertCell(newRowObj.cells.length);
     var newColButton=newRowObj.insertCell(newRowObj.cells.length);
     
     newColName.innerHTML=document.getElementById("newName").value;
     newColAge.innerHTML=document.getElementById("newAge").value;
     newColButton.innerHTML='<input type="button" value="删除" >';
  }
</script>
</head>
<body>
<table width="100%" id="mytable" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>姓名</td>
    <td>年龄</td>
    <td>操作</td>
  </tr>
  
</table>
<input type="text" name="name" id="newName" />
<input type="text" name="age" id="newAge"/>
<input type="button"   value="新增"/>
</body>
</html>
posted @ 2009-08-07 08:18  与时俱进  阅读(267)  评论(0编辑  收藏  举报
友情链接:同里老宅院民居客栈