JS中提示数组为空或不是对象,求大神,在线等!

var locationArray =new Array;
function mineCoordinate(mineNum,rowCoord,colCoord)//创建不同
大小的数组
{
locationArray.length=0;//重置数组
for(var num=0; num<mineNum;num++)
{
var x=Math.round(Math.random()*rowCoord);
var y=Math.round(Math.random()*colCoord);
locationArray.push([x,y]);
}
alert("创建成功"+locationArray.length);
}
function mineLocation()
{
switch (tableNode.rows[0].cells.length)
{
case 6:
mineCoordinate(5,5,5);
break;
case 12:
mineCoordinate(20,11,11);
break;
case 21:
mineCoordinate(18,14,20);
break;
case 33:
mineCoordinate(28,15,32);
break;
default:
alert("未知错误");
break;
}
}
function mineVisible(mineNum)
{
var row=event.srcElement.parentNode.rowIndex;
var col=event.srcElement.cellIndex;
for(var temp=0;temp<mineNum;temp++)
{
if(locationArray[temp][0]==row && locationArray[temp][1]
==col)//问题出在这里:会提示数组为空或不是对象,哪里错了呢?????
{
clearInterval(timeInterval);
for(var temp1=0;temp1<mineNum;temp1++)
{
var xRow=locationArray[temp1][0];
var xCol=locationArray[temp1][1];
tableNode.rows[xRow].cells[xCol].innerHTML="<img
src='img/123.jpg' height='19' width='16'/>";
}
return;
}
}
}

locationArray[temp]不是有效的数组,可能locationArray为空,或者temp操出了locationArray的索引。

for(var temp=0;temp<mineNum;temp++){
    console.log(locationArray[temp]);//你可以输出看看,console.log函数不能在IE下使用

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网