Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获类型错误:无法读取属性';追加儿童';空值?_Javascript_Html_Two.js - Fatal编程技术网

Javascript 未捕获类型错误:无法读取属性';追加儿童';空值?

Javascript 未捕获类型错误:无法读取属性';追加儿童';空值?,javascript,html,two.js,Javascript,Html,Two.js,错误 错误发生在two.js中的这一行 two.js:3390 Uncaught TypeError: Cannot read property 'appendChild' of null at root.Two.appendTo (two.js:3390) at test2.html:14 这是我的密码 elem.appendChild(this.renderer.domElement); var elem=document.getElementById('draw-shapes');

错误

错误发生在two.js中的这一行

two.js:3390 Uncaught TypeError: Cannot read property 'appendChild' of null
at root.Two.appendTo (two.js:3390)
at test2.html:14
这是我的密码

elem.appendChild(this.renderer.domElement);

var elem=document.getElementById('draw-shapes');
var参数={宽度:285,高度:200};
var two=新的two(参数).appendTo(元素);
var circle=2.makeCircle(72,100,50);
circle.fill='#FF8000';
circle.stroke='oranged';
圆形。线宽=5;
二、更新();

我刚开始学习Javascript。如何解决此问题?

您的
elem
变量为
null
,因为没有id为
的元素绘制形状。html正文中唯一的元素是脚本标记

您可以在html正文中创建
div

<!DOCTYPE html>
<html>
<head>

<script src="./two.js"></script>


</head>

<body>
<script>
var elem = document.getElementById('draw-shapes');
var params = { width: 285, height: 200 };
var two = new Two(params).appendTo(elem);

var circle = two.makeCircle(72, 100, 50);

circle.fill = '#FF8000';
circle.stroke = 'orangered'; 
circle.linewidth = 5;

two.update();
</script>
</body>
</html>

您的
elem
变量为
null
,因为没有id为
draw shapes
的元素。html正文中唯一的元素是脚本标记

您可以在html正文中创建
div

<!DOCTYPE html>
<html>
<head>

<script src="./two.js"></script>


</head>

<body>
<script>
var elem = document.getElementById('draw-shapes');
var params = { width: 285, height: 200 };
var two = new Two(params).appendTo(elem);

var circle = two.makeCircle(72, 100, 50);

circle.fill = '#FF8000';
circle.stroke = 'orangered'; 
circle.linewidth = 5;

two.update();
</script>
</body>
</html>

HTML中似乎没有任何id为“draw-shapes”的元素。问题是
elem
未定义,可能是因为调用
document.getElementById('draw-shapes')
@L.Vadim no时没有id为
draw-shapes的元素,这是不必要的;“two.js”是一个公开可用的库,在这里可能没有问题。什么是渲染器?HTML中似乎没有任何id为“draw shapes”的元素。问题是
elem
未定义,可能是因为调用
document.getElementById时没有id为
draw shapes
的元素('draw-shapes')
@L.Vadim no这不是必需的;“two.js”是一个公开可用的库,在这里可能没有问题。渲染器是什么?
var elem = document.body;
...
var two = new Two(params).appendTo(elem);