未捕获的TypeError:无法读取null的属性'appendChild'?

时间:2017-01-15 14:49:18

标签: javascript html two.js

错误

two.js:3390 Uncaught TypeError: Cannot read property 'appendChild' of null
at root.Two.appendTo (two.js:3390)
at test2.html:14

错误发生在two.js

中的这一行
elem.appendChild(this.renderer.domElement);

这是我的代码

<!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>

我刚开始学习Javascript。怎么解决这个???

1 个答案:

答案 0 :(得分:0)

您的变量为library(tidyverse) year<-c("2000","2000","2001","2002","2000","2002") weight<-c(0.5,0.7,0.8,0.7,0.6,0.9) YG<-data.frame(year,weight) w<-data.frame(YG %>% group_by(year) %>% summarise(n = round(sum(weight)), g = n()) %>% select(-g) %>% spread(year, n, fill = 0)) ,因为没有ID为elem的元素。 html正文中唯一的元素是脚本标记。

您可以在html正文中输入null

draw-shapes

或将“ Two”实例添加到主体中,如下所示:

div