<!DOCTYPE?html>
<html>
<head>
<meta?charset="UTF-8">
<title>Document</title>
<style?type="text/css">
table?{margin:20px;}
table?th,table?tr?td{border:1px?solid?black;padding:20px;}
</style>
<script?type="text/javascript">
window.onload=function(){
var?adBtn=document.getElementById('btn1');
var?oTab=document.getElementById('tab1');
var?oTbody=document.getElementsByTagName('tbody')[0];
var?oTh=document.getElementsByTagName('th');
var?oTd=document.getElementsByTagName('td');
var?oTr=oTbody.getElementsByTagName('tr');
for(var?i=0;i<oTr.length;i++){
var?oldColor="";
oTr[i].onmouseover=function(){
oldColor=this.style.background;
this.style.background="blue";
}
oTr[i].onmouseout=function(){
this.style.background=oldColor;
}
if(i%2==0){
oTr[i].style.background="red";
}
}
adBtn.onclick=function?(){
var?cTr=document.createElement('tr');
var?cTd=document.createElement('td');
cTr.appendChild(cTd);
oTab.oTbody.appendChild(cTr);?????//請(qǐng)問我這里哪里寫錯(cuò)了。。
}
}
</script>
</head>
<body>
姓名<input?type="text"?name="">
年齡<input?type="text"?name="">
<input?type="button"?value="添加"?id="btn1">
<table?id="tab1">
<thead>
<tr>
<th>編號(hào)</th>
<th>姓名</th>
<th>身高</th>
<th>編輯</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>張三</td>
<td>170</td>
<td></td>
</tr>
<tr>
<td>2</td>
<td>李四</td>
<td>171</td>
<td></td>
</tr>
<tr>
<td>3</td>
<td>王五</td>
<td>172</td>
<td></td>
</tr>
</tbody>
</table>
</body>
</html>為啥我點(diǎn)添加沒有反應(yīng)。。。 希望前輩們幫幫我??!1
求教關(guān)于appenChild的問題?。?!
超級(jí)巨浪大切
2017-12-08 18:07:37