<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
window.onload=function(){
var otab=document.getElementById("tab");
var txt1=document.getElementById("name");
var txt2=document.getElementById("age");
var btn=document.getElementById("bt")
var oid=otab.tBodies[0].rows.length+1;
}
btn.onclick=function(){
var otr=document.createElement("tr");
var otd=document.createElement("td");
otd.innerHTML=oid++;
otr.appendChild(otd);
var otd=document.createElement("td");
otd.innerHTML=txt1.value;
otr.appendChild(otd);
var otd=document.createElement("td");
otd.innerHTML=txt2.value;
otr.appendChild(otd);
var otd=document.createElement("td");
otd.innerHTML='<a herf="javscript:;">删除<a>';
otr.appendChild(otd);
otd.document.getElementsByTagName("a")[0].onclick=function(){
}
otab.tBodies[0].appendChild(tr);
}
</script>
</head>
<body>
<input type="text" id="name"/>
<input type="text" id="age"/>
<input type="button" value="添加" id="bt"/>
<table border="1" cellspacing="" cellpadding="" id="tab" style="width: 400px;">
<thead>
<td>ID</td>
<td>姓名
</td>
<td>年龄</td>
<td>操作</td>
</thead>
<tbody>
<tr>
<td>1</td>
<td>一</td>
<td>10</td>
<td></td>
</tr>
<tr>
<td>2</td>
<td>二</td>
<td>20</td>
<td></td>
</tr>
<tr>
<td>3</td>
<td>三</td>
<td>30</td>
<td></td>
</tr>
<tr>
<td>4</td>
<td>四</td>
<td>40</td>
<td></td>
</tr>
<tr>
<td>5</td>
<td>五</td>
<td>50</td>
<td></td>
</tr>
</tbody>
</table>
</body>
</html>
慕粉3769977
相关分类