<!DOCTYPE html><html><head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>DOM方法</title> <link rel="stylesheet" href=""> <script> var ele = document.createElement('div'); var txt = document.createTextNode('textContent'); ele.appendChild(txt); document.getElementsByTagName('body')[0].appendChild(ele); //console中运行没有问题,执行这段语句的时候就报错 </script></head><body></body></html>报错是出在 document.getElementsByTagName('body')[0]appendChild(ele)这句话,显示错误:Uncaught TypeError: Cannot read property 'appendChild' of undefined新手,找了半天不知到错在哪了,求解答。谢谢各位 !
添加回答
举报
0/150
提交
取消