少年阿宾

那些青春的岁月

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>javascript实现表格动态增加删除</title>

<script>
 function addline() {
  var tb = document.getElementById("mytable");
  var row = tb.insertRow(tb.rows.length);
  var colname = row.insertCell(row.cells.length);
  var colage = row.insertCell(row.cells.length);
  var colbutton = row.insertCell(row.cells.length);

  colname.innerHTML = document.getElementById("name1").value;
  colage.innerHTML = document.getElementById("age1").value;
  colbutton.innerHTML = '<input type="button" value="删除" onclick="deleteRow('
    + (tb.rows.length - 1) + ')" />'
 }
 function deleteRow(index) {
  var tb = document.getElementById("mytable");
  tb.deleteRow(index);
 }
</script>
<body>
 <table id="mytable" border="1">
  <tr>
   <td>NAME</td>
   <td>AGE</td>
   <td>OPERATE</td>
  </tr>
 </table>
 <input type="text" name="name" id="name1" />
 <input type="text" name="age" id="age1" />
 <input type="button" value="PRESS" onclick="return addline();" />
</body>
</html>

posted on 2012-08-28 23:21 abin 阅读(805) 评论(0)  编辑  收藏 所属分类: Javascript

只有注册用户登录后才能发表评论。


网站导航: