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="<imgsrc='img/123.jpg' height='19' width='16'/>";}return;}}}
1 回答

動漫人物
TA貢獻1815條經驗 獲得超10個贊
locationArray[temp]不是有效的數組,可能locationArray為空,或者temp操出了locationArray的索引。
for ( var temp=0;temp<mineNum;temp++){ console.log(locationArray[temp]); //你可以輸出看看,console.log函數不能在IE下使用 |
添加回答
舉報
0/150
提交
取消