2 wf13111343 wf13111343 于 2014.07.18 15:43 提问

为什么setinterval(fall,200)被 tire_table.rows。。。运行?

var tire_rows=20;
var tire_cols=15;
var cell_size =100;
function test(rows,cols,cellwidth,cellheight){

var table =document.createElement("table");
for(var i=0;i<rows;i++)
{
    var row=table.insertRow(i);
    for(var j=0;j<cols;j++)
        {
           var cell =row.insertCell(j);
           cell.style.cellwidth+"px";
           cell.style.cellheight+"px";
        }
}

return table;

}

var tire_table;
var currentfall =[
{x:tire_cols/2-1,y:0},
{x:tire_cols/2,y:0},
{x:tire_cols/2,y:1},
{x:tire_cols/2+1,y:1},

              ];

window.onload =function()
{
var tire_table= test(tire_rows,tire_cols,800,600);
tire_table.border=1;
tire_table.style.borderCollapse="collapse";
document.body.appendChild(tire_table);

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

  var cur =currentfall[i];
  tire_table.rows[cur.y].cells[cur.x].style.backgroundColor ="blue";

}

setInterval(fall,1000);

};

function fall()
{

for(var i=0;i<currentfall.length;i++)
{     
  var cur =currentfall[i];    
  tire_table.rows[cur.y].cells[cur.x].style.backgroundColor ="white";

}


var canfall=false;

for(var i=0;i<currentfall.length;i++)
{
  var cur =currentfall[i];
  if(cur.y>=tire_rows-1)
  {
      canfall =false;

      break;
  }
}


if (canfall) {
    for ( var i = 0; i < currentfall.length; i++) {
        var cur = currentfall[i];
        cur.y++;

    }
}



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

  var cur =currentfall[i];

  tire_table.rows[cur.y].cells[cur.x].style.backgroundColor ="blue";

}

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!