为了账号安全,请及时绑定邮箱和手机立即绑定

求教关于appenChild的问题!!!

求教关于appenChild的问题!!!

超级巨浪大切 2017-12-08 18:07:37
<!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);     //请问我这里哪里写错了。。 } } </script> </head> <body> 姓名<input type="text" name=""> 年龄<input type="text" name=""> <input type="button" value="添加" id="btn1"> <table id="tab1"> <thead> <tr> <th>编号</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>为啥我点添加没有反应。。。 希望前辈们帮帮我!!1
查看完整描述

1 回答

?
超级巨浪大切

TA贡献2条经验 获得超0个赞

已解决 谢谢!

查看完整回答
反对 回复 2017-12-08
  • 1 回答
  • 0 关注
  • 1100 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信