小编Cam*_*m C的帖子

JS错误消息textContent设置为null

我对JS和Web开发世界都很陌生,所以如果我的问题有点乏味,请提前道歉.

我写了这段代码:

var breakfast = new Object();
breakfast.food = "croissant";
breakfast.extra = ["mushroom", "cheese"];
breakfast.eat = function(){return this.food + " with " +  this.extra[0];}
var elBreakfast = document.getElementById("breakf");
elBreakfast.textContent = breakfast.eat();
Run Code Online (Sandbox Code Playgroud)

我从浏览器收到错误消息:

"Uncaught TypeError: Cannot set property 'textContent' of null"... 
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

谢谢!

javascript

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

javascript ×1