找不到目標(biāo)元素,大神們求解("Uncaught TypeError: Cannot read property 'appendChild' of null")
var initDiv = function(container, data, divs) {
for(var i = 0; i < data.length; i++) {
var div = [];
for(var j = 0; j < data[0].length; j++) {
var newNode = document.createElement('div');
newNode.className = 'none';
newNode.style.top = (i * 20) + 'px';
newNode.style.left = (j * 20) + 'px';
container.appendChild(newNode);
div.push(newNode);
}?
divs.push(div);
}
}
2020-04-10
在initDiv(container,data,divs)?不是傳了三個參數(shù)嗎?,根據(jù)報錯,你看看game.js中調(diào)用的initDiv(gameDiv,gameData,gameDivs)是不是有位置出現(xiàn)錯誤,如果沒錯,那就是gamediv獲取對象時錯了,你看看那個local.js
2020-03-07
在引入js的時候 后面加上? defer="true"? 就可以了
2019-12-30
傳進(jìn)來的container看看是怎么寫的。我也是這么傳參的,測試沒有問題。container是傳的document.getElementById("");