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

问题会提示数组为空或不是对象,哪里错了呢?

问题会提示数组为空或不是对象,哪里错了呢?

一只萌萌小番薯 2022-07-26 15:11:55
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下使用


查看完整回答
反对 回复 2022-08-01
  • 1 回答
  • 0 关注
  • 120 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号