<!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 table1=document.createElement("table");
var row=table1.insertRow();
var td1=row.insertCell();
td1.innerHTML=document.getElementById("name1").value;
var td2=row.insertCell();
td2.innerHTML=document.getElementById("age1").value;
var td3=row.insertCell();
td3.innerHTML='<input type="button" value="删除" onclick="deleteRow(this.parentElement)" />';
document.getElementById("div1").appendChild(table1);
table1.setAttribute('border','1');
}
function deleteRow(obj) {
obj.parentElement.removeChild(obj);
}
</script>
<body>
<div id="div1" style="">
</div>
<input type="text" name="name" id="name1" />
<input type="text" name="age" id="age1" />
<input type="button" value="PRESS" onclick="return addline();" />
</body>
</html>