为了账号安全,请及时绑定邮箱和手机立即绑定

我的字体颜色和背景颜色都不是按我不是按我设置的来的

代码如下function updateBoardView(){
 $(".num").remove();
 for(var i=0; i<4; i++){
  for(var j=0; j<4; j++){ 
   var numId=$("#num-"+i+"-"+j);
   $("#container").append('<div class="num" id="num-'+i+'-'+j+'"></div>');
   if(board[i][j]!=0){
    numId.css('height','100px');
    numId.css('width','100px');
    numId.css('top',getPosTop(i,j));
    numId.css('left',getPosLeft(i,j));
    numId.css('background-color',getNumBackgroundColor(board[i][j]));
    numId.css('color',getFontColor(board[i][j]));
    
    numId.text(board[i][j]); 
   }
   else{
    numId.css('height','0px');
    numId.css('width','0px');
    numId.css('top',getPosTop(i,j)+50);
    numId.css('left',getPosLeft(i,j)+50);
   }
  }
 }
}

----------------------------------------------

function getNumBackgroundColor(num){
 switch(num){
   case 2: return "#eee4da";
   case 4: return "#ede0c8";
      case 8: return "#f2b179";
      case 16: return "#f59563";
      case 32: return "#f67c5f";
      case 64: return "#f65e3b";
      case 128: return "#edcf72";
      case 256: return "#edcc61";
      case 512: return "#9c0";
      case 1024: return "#33b5e5";
      case 2048: return "#09c";
      case 4096: return "#a6c";
      case 8192: return "#93c";
 }
 return "black";
}

function getFontColor(num){
 if(num>4)
  return "white";
 else
     return "#776e65";
  
}


正在回答

1 回答

老师我找到问题了,不过这个if判断里是不是可以不用写东西

if(board[i][j]!=0){
    numId.css('height','100px');
    numId.css('width','100px');
    numId.css('top',getPosTop(i,j));
    numId.css('left',getPosLeft(i,j));
    numId.css('background-color',getNumBackgroundColor(board[i][j]));
    numId.css('color',getFontColor(board[i][j]));
    
    numId.text(board[i][j]); 
   }

它里面根本就不会执行啊!

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信