js写完后不显示方块

来源:2-2 界面渲染逻辑

马博卖假奶

2019-10-01 18:40

var nextData=[

[2,2,0,0],

[0,2,2,0],

[0,0,0,0],

[0,0,0,0]

];

var gameData=[

[0,0,0,0,0,0,0,0,0,0],

[0,0,0,0,0,0,0,0,0,0],

[0,0,0,0,0,0,0,0,0,0],

[0,0,0,0,0,0,0,0,0,0],

[0,0,0,0,0,0,0,0,0,0],

[0,0,0,0,0,0,0,0,0,0],

[0,0,0,0,0,0,0,0,0,0],

[0,0,0,0,0,2,1,0,0,0],

[0,0,0,2,2,2,1,0,0,0],

[0,0,1,1,1,1,1,0,0,0]


];

var nextDivs=[];

var gameDivs=[];

var initGame=function(){

for(var i=0;i<gameData.length;i++){

var gameDiv=[];

for(var j=0;j<gameData[0].length;j++){

var newNode=document.createElement('div');

newNode.className='none';

newNode.style.top=(i*20)+'px';

newNode.style.left=(j*20)+'px';

document.getElementById('game').appendChild(newNode);

gameDiv.push(newNode);

}

gameDivs.push(gameDiv);

}

}

var initNext=function(){

for(var i=0;i<nextData.length;i++){

var nextDiv=[];

for(var j=0;j<nextData[0].length;j++){

var newNode=document.createElement('div');

newNode.className='none';

newNode.style.top=(i*20)+'px';

newNode.style.left=(j*20)+'px';

document.getElementById('next').appendChild(newNode);

nextDiv.push(newNode);

}

nextDivs.push(nextDiv);

}

}


var refreshGame=function(){

for(var i=0;i<gameData.length;i++){

for(var j=0;j<gameData[0].length;j++){

if(gameData[i][j]==0){

gameDivs[i][j].className='none';

}else if(gamedata[i][j]==1){

gameDivs[i][j].className='done';

}else if(gameData[i][j]==2){

gameDivs[i][j].className='current';

}

}

}

}

var refreshNext=function(){

for(var i=0;i<nextData.length;i++){

for(var j=0;j<nextData[0].length;j++){

if(nextData[i][j]==0){

nextDivs[i][j].className='none';

}else if(nextdata[i][j]==1){

nextDivs[i][j].className='done';

}else if(nextData[i][j]==2){

nextDivs[i][j].className='current';

}

}

}

}

initGame();

initNext();

refreshGame();

refreshNext();

http://img1.mukewang.com/5d932cbc0001842906800104.jpg

http://img.mukewang.com/5d932ce50001ceba03790055.jpg
http://img1.mukewang.com/5d932cf80001b29801600039.jpg


找了半天没找到








写回答 关注

2回答

  • qq_慕斯4517609
    2020-07-22 20:58:44

    命名错误。gameData 写成gamedata了

  • Standpoint
    2019-10-10 21:43:32

    发生这种情况的原因是因为获取不到插入的节点。就是在获取节点的时候,节点还没有加载。在index.html文件中将<script>引用放在<body>后面就行了

    马博卖假奶

    我把script引用放在后面还是没有变化 报错还是之前那个

    2019-10-26 15:37:38

    共 1 条回复 >

基于websocket的火拼俄罗斯(单机版)

前端大牛带你实现单机版俄罗斯方块!

31676 学习 · 106 问题

查看课程

相似问题