appendChild() 不是函数
appendChild() is not a function
我在codepen.io上试了一下小笔(这里是mine <3),
代码如下:
var body = $('body');
var container = document.getElementsByTagName("container");
var tileTab = new Array();
var windowWidth = window.innerWidth;
var windowHeight = window.innerHeight;
var nbTileWidth = Math.floor(windowWidth / 50) - 1;
var nbTileHeight = Math.floor(windowHeight / 50) - 1;
var x = 0;
for(var i = 0; i < nbTileHeight; i++){
var row = document.createElement("div");
for(var j = 0; j < nbTileWidth; j++){
tileTab[x] = document.createElement("div");
row.appendChild(tileTab[x]);
tileTab[x].className = "tile";
x++;
}
container.appendChild(row);
row.className = "row";
}
body.appendChild(container);
这支笔在这里可用:codepen
控制台return我
container.appendChild is not a function
我用 jQuery 试过了,但结果是一样的:/。
抱歉 post 这似乎是一个基本问题,但现在我不知道这里出了什么问题。提前!
替换这些行:
var body = $('body');
var container = document.getElementsByTagName("container");
这些:
var body = document.body;
var container = document.querySelector('.container');
我在codepen.io上试了一下小笔(这里是mine <3),
代码如下:
var body = $('body');
var container = document.getElementsByTagName("container");
var tileTab = new Array();
var windowWidth = window.innerWidth;
var windowHeight = window.innerHeight;
var nbTileWidth = Math.floor(windowWidth / 50) - 1;
var nbTileHeight = Math.floor(windowHeight / 50) - 1;
var x = 0;
for(var i = 0; i < nbTileHeight; i++){
var row = document.createElement("div");
for(var j = 0; j < nbTileWidth; j++){
tileTab[x] = document.createElement("div");
row.appendChild(tileTab[x]);
tileTab[x].className = "tile";
x++;
}
container.appendChild(row);
row.className = "row";
}
body.appendChild(container);
这支笔在这里可用:codepen
控制台return我
container.appendChild is not a function
我用 jQuery 试过了,但结果是一样的:/。
抱歉 post 这似乎是一个基本问题,但现在我不知道这里出了什么问题。提前!
替换这些行:
var body = $('body');
var container = document.getElementsByTagName("container");
这些:
var body = document.body;
var container = document.querySelector('.container');