日期:2014-05-16 浏览次数:20409 次
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<p>
<table width="600" align="center" border="1">
<tbody id="t">
<tr>
<td><input type="text"/></td>
<td><input id="button" type="button" value="添加一行" onClick="addButton()" /></td>
</tr>
</tbody>
</table>
</p>
<script language="javascript">
function addButton(){
var tr = document.createElement("tr");
var td1 = document.createElement("td");
var td2 = document.createElement("td");
var in1 = document.createElement("input");
var in2 = document.createElement("input");
var in3 = document.createElement("input");
in1.setAttribute("type","button");
in2.setAttribute("type","text");
in1.setAttribute("value","添加");
/*
in1.onClick=function(){
addButton();
};*/
//in1.attachEvent("onClick",addButton);
in1.setAttribute("onclick","addButton()");
in3.setAttribute("type","button");
in3.setAttribute("value","删除");
in3.setAttribute("onclick","deButton(this)");
td2.appendChild(in3);
td1.appendChild(in2);
td2.appendChild(in1);
tr.appendChild(td1);
tr.appendChild(td2);
document.getElementById("t").appendChild(tr);
}
function deButton(obj){
var p = obj.parentNode.parentNode;
p.parentNode.removeChild(p);
}
</script>
</body>
</html>
function addButton(){
var tr="<tr><td><input type='text'/></td><td><input id='button' type='button' value='添加一行'