<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script>
window.onload=function(){
var oTab=document.getElementById("tab1");
var oldColor='';
alert(oTab.tBodies[0].rows[0]); for(var i=0;i<oTab.tBodies[0].rows.length;i++){
oTab.tBodies[0].rows[i].onmouseover=function(){
oldColor=this.style.background;
this.style.background="green";
}
oTab.tBodies[0].rows[i].onmouseout=function(){
this.style.background=oldColor;
}
if(i%2==0){
oTab.tBodies[0].rows[i].style.background="#CCC";
}
else{
oTab.tBodies[0].rows[i].style.background="";
}
}
var oName=document.getElementById("name");
var oAge=document.getElementById("age");
var oAdd=document.getElementById("add");
oAdd.onclick=function (){
var oTr=document.createElement("tr");

var oTd=document.createElement("td");
oTd.innerHTML=oTab.tBodies[0].rows.length+1;
alert(oTd);
oTr.appendChild(oTd);

var oTd=document.createElement("td");
oTd.innerHTML=oName.value;
oTr.appendChild(oTd);

var oTd=document.createElement("td");
oTd.innerHTML=oAge.value;
oTr.appendChild(oTd);
alert(oTr);
oTab.tBodies[0].appendChild[oTr];
}
}
</script>
</head><body>
姓名:<input id="name" type="text"/>
年龄:<input id="age" type="text"/>
<input id="add" type="button" value="添加" />
<table id ="tab1" border="1" width="500px">
<thead>
<td>Id</td>
<td>姓名</td>
<td>年龄</td>
</thead>
<tbody>
   <tr>
    <td>1</td>
<td>Blue</td>
<td>27</td>
   </tr>
   <tr>
    <td>2</td>
<td>张三</td>
<td>23</td>
   </tr>
   <tr>
    <td>3</td>
<td>李四</td>
<td>28</td>
   </tr>
   <tr>
    <td>4</td>
<td>Jack</td>
<td>27</td>
   </tr>
</tbody>
   </table>
</body></html>
关于表格添加的代码
为什么添加不了元素,大牛们能给我看看代码吗?表格