控制台报错
代码
window.onload = function(){
var para = document.createElement("p");
var testp = document.getElementById("testp");
testp.appendChild(para);
var txt = document.createTextNode("Hello world");
para.appendChild(txt);
}
Uncaught TypeError: Cannot read property 'appendChild' of null
at window.onload (test.js:4)
window.onload @ test.js:4
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
建议贴上你的html,报错的地方应该是你的testp获取不正确,你可以把testp打印出来看一下。
我估摸着是你没有这个
id为testp的元素,或者写错了。