我想只有JavaScript元素 创建一个画布,但我发现了一个错误:通过JavaScript元素在创作油画的误差
Uncaught TypeError: Cannot read property 'appendChild' of null
我的JavaScript代码是:
// create the canvas on the page :
var myPageCanvas = document.createElement("canvas");
// Assigne Id to thin canvas :
myPageCanvas.id = 'c';
// custumize canvas :
myPageCanvas.height = 300;
myPageCanvas.width = 500;
myPageCanvas.style.display = "block";
myPageCanvas.style.margin = "50px auto";
// Add the canvas on the page :
document.body.appendChild(myPageCanvas);
你复制和粘贴代码,或者你重写了它?我在代码中看不到任何问题。 – youssouf
当我使用谷歌浏览器的控制台,说这是不能读属性'appendChild'null,我的代码是在问题=) –
您的网页似乎确实包含
元素或您没有关闭标记。 – youssouf